Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/items/external-blocks.md

@tgross35 tgross35 Jun 28, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would be good to have an example at src/inline-assembly.md alongside naked functions?

View changes since the review

@tgross35 tgross35 Jun 28, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somewhere in the reference it would probably be good to clarify the purpose of parameters and return types in extern "custom" definitions, since they don't directly serve any purpose. I feel like we discussed this somewhere but can't seem to find it.

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We actually disallow them entirely

error: invalid signature for `extern "custom"` function
 --> <source>:6:31
  |
6 | unsafe extern "custom" fn foo(a: i32) -> i32 {
  |                               ^^^^^^     ^^^
  |
  = note: functions with the "custom" ABI cannot have any parameters or return type
help: remove the parameters and return type
  |
6 - unsafe extern "custom" fn foo(a: i32) -> i32 {
6 + unsafe extern "custom" fn foo() {
  |

Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ r[items.extern.fn.param-patterns]
Patterns are not allowed in parameters, only [IDENTIFIER] or `_` may be used.

r[items.extern.fn.qualifiers]
The `safe` and `unsafe` function qualifiers are allowed, but other function qualifiers (e.g. `const`, `async`, `extern`) are not.
The `safe` and `unsafe` function qualifiers are allowed, but other function qualifiers (e.g. `const`, `async`, `extern`) are not. The `safe` qualifier is rejected in `extern "custom"` blocks.

r[items.extern.fn.foreign-abi]
Functions within external blocks may be called by Rust code, just like functions defined in Rust. The Rust compiler automatically translates between the Rust ABI and the foreign ABI.
Expand Down Expand Up @@ -112,6 +112,9 @@ r[items.extern.abi.system]
r[items.extern.abi.unwind]
* `extern "C-unwind"` and `extern "system-unwind"` --- Identical to `"C"` and `"system"`, respectively, but with [different behavior][unwind-behavior] when the callee unwinds (by panicking or throwing a C++ style exception).

r[items.extern.abi.custom]
* `unsafe extern "custom"` --- A custom ABI that is not known to the rust compiler.

r[items.extern.abi.platform]
There are also some platform-specific ABI strings:

Expand Down
11 changes: 11 additions & 0 deletions src/items/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,15 @@ With `panic=unwind`, when a `panic` is turned into an abort by a non-unwinding A

For other considerations and limitations regarding unwinding across FFI boundaries, see the [relevant section in the Panic documentation][panic-ffi].

r[items.fn.extern.custom]
An `extern "custom"` function has an unknown, custom ABI. The only way to call such a function is via [inline assembly].

@tgross35 tgross35 Jun 28, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a usage hint:

... unknown, custom ABI. This can be used to implement calling conventions unsupported by rustc. The only way to call such a function is via [inline assembly].

View changes since the review


r[items.fn.extern.custom.safety]
An `extern "custom"` function must be `unsafe`.

r[items.fn.extern.custom.naked]
An `extern "custom"` function definition must be a [naked function].

[forced-unwinding]: https://rust-lang.github.io/rfcs/2945-c-unwind-abi.html#forced-unwinding
[panic handler]: ../panic.md#the-panic_handler-attribute
[panic-ffi]: ../panic.md#unwinding-across-ffi-boundaries
Expand Down Expand Up @@ -411,6 +420,7 @@ fn foo_oof(#[some_inert_attribute] arg: u8) {
[testing attributes]: ../attributes/testing.md
[`cold`]: ../attributes/codegen.md#the-cold-attribute
[`inline`]: ../attributes/codegen.md#the-inline-attribute
[naked function]: ../attributes/codegen.md#the-naked-attribute
[`deprecated`]: ../attributes/diagnostics.md#the-deprecated-attribute
[`doc`]: ../../rustdoc/the-doc-attribute.html
[`must_use`]: ../attributes/diagnostics.md#the-must_use-attribute
Expand All @@ -427,3 +437,4 @@ fn foo_oof(#[some_inert_attribute] arg: u8) {
[variadic function]: external-blocks.md#variadic-functions
[`extern` block]: external-blocks.md
[zero-sized]: glossary.zst
[inline assembly]: ../inline-assembly.md
Loading