Skip to content

add extern "custom"#2300

Draft
folkertdev wants to merge 1 commit into
rust-lang:masterfrom
folkertdev:extern-custom
Draft

add extern "custom"#2300
folkertdev wants to merge 1 commit into
rust-lang:masterfrom
folkertdev:extern-custom

Conversation

@folkertdev

Copy link
Copy Markdown
Contributor

stabilization PR: rust-lang/rust#158504

This is a tricky one that is an exception to some rules. I've tried to put the raw information in, but this'll probably require some refinement.

@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

Comment thread src/items/functions.md
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

@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() {
  |

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants