Skip to content

add extern "custom" - #2300

Draft
folkertdev wants to merge 3 commits into
rust-lang:masterfrom
folkertdev:extern-custom
Draft

add extern "custom"#2300
folkertdev wants to merge 3 commits 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() {
  |

@ehuss ehuss added the S-waiting-on-stabilization Waiting for a stabilization PR to be merged in the main Rust repository label Jul 28, 2026
Comment thread src/items/external-blocks.md Outdated
Comment thread src/items/functions.md
Comment on lines +242 to +250
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].

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].

@traviscross traviscross Jul 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.

We need to add the rules here about what's allowed or not allowed in terms of parameters and return types.

View changes since the review

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.

@rustbot author

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.

And we need to add text about the function pointer restrictions as well.

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.

where should that function pointer text go? Here on the item and/or in external-blocks.md, or somewhere else?

@rustbot rustbot added the S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author. label Jul 28, 2026
@rustbot

rustbot commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

folkertdev and others added 2 commits July 29, 2026 13:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author. S-waiting-on-stabilization Waiting for a stabilization PR to be merged in the main Rust repository

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants