Skip to content

Add extern "custom" - #3980

Open
folkertdev wants to merge 7 commits into
rust-lang:masterfrom
folkertdev:extern-custom-rfc
Open

Add extern "custom"#3980
folkertdev wants to merge 7 commits into
rust-lang:masterfrom
folkertdev:extern-custom-rfc

Conversation

@folkertdev

@folkertdev folkertdev commented Jul 1, 2026

Copy link
Copy Markdown

View all comments

Summary

An extern "custom" fn is a function with a custom ABI that is unknown to rust. Often these are low-level functions that pass arguments in different registers than any standard calling convention.

#[unsafe(naked)]
pub unsafe extern "custom" fn __aeabi_uidivmod() {
    core::arch::naked_asm!(
        "push {{lr}}",
        "sub sp, sp, #4",
        "mov r2, sp",
        "bl {trampoline}",
        "ldr r1, [sp]",
        "add sp, sp, #4",
        "pop {{pc}}",
        trampoline = sym crate::arm::__udivmodsi4
    );
}

unsafe extern "custom" {
	fn __fentry__();
}

History

Important

Since RFCs involve many conversations at once that can be difficult to follow, please use review comment threads on the text changes instead of direct comments on the RFC.

If you don't have a particular section of the RFC to comment on, you can click on the "Comment on this file" button on the top-right corner of the diff, to the right of the "Viewed" checkbox. This will create a separate thread even if others have commented on the file too.

Rendered

@folkertdev folkertdev changed the title add extern "custom" RFC add extern "custom" Jul 1, 2026
@folkertdev folkertdev added the I-lang-nominated Indicates that an issue has been nominated for prioritizing at the next lang team meeting. label Jul 1, 2026
@traviscross traviscross added the T-lang Relevant to the language team, which will review and decide on the RFC. label Jul 1, 2026
@traviscross

Copy link
Copy Markdown
Contributor

Thanks @folkertdev for putting this together.

@rfcbot fcp merge lang

@traviscross traviscross added the P-lang-drag-1 Lang team prioritization drag level 1. label Jul 1, 2026
@rust-rfcbot

rust-rfcbot commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

@traviscross has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns.
See this document for info about what commands tagged team members can give me.

@rust-rfcbot rust-rfcbot added proposed-final-comment-period Currently awaiting signoff of all team members in order to enter the final comment period. disposition-merge This RFC is in PFCP or FCP with a disposition to merge it. labels Jul 1, 2026
@tmandry

tmandry commented Jul 1, 2026

Copy link
Copy Markdown
Member

@rfcbot reviewed

@rust-rfcbot rust-rfcbot added final-comment-period Will be merged/postponed/closed in ~10 calendar days unless new substational objections are raised. and removed proposed-final-comment-period Currently awaiting signoff of all team members in order to enter the final comment period. labels Jul 1, 2026
@rust-rfcbot

Copy link
Copy Markdown
Collaborator

🔔 This is now entering its final comment period, as per the review above. 🔔

Comment thread text/0000-extern-custom.md Outdated
@traviscross traviscross changed the title add extern "custom" Add extern "custom" Jul 1, 2026
@traviscross traviscross added I-lang-radar Items that are on lang's radar and will need eventual work or consideration. and removed I-lang-nominated Indicates that an issue has been nominated for prioritizing at the next lang team meeting. P-lang-drag-1 Lang team prioritization drag level 1. labels Jul 1, 2026
@nikomatsakis

Copy link
Copy Markdown
Contributor

@rfcbot reviewed

@ChayimFriedman2

Copy link
Copy Markdown

Seeing a RFC entering a final comment period 1 hour after it was opened is extremely rare, and personally makes me worried. Even if it was discussed extensively in the past and all relevant team members are on-board, I believe we should let the community more time to discuss it.

Comment thread text/3980-extern-custom.md
@programmerjake

Copy link
Copy Markdown
Member

imo it's fine since that's what the final comment period is for, announcing and giving people time to look at something before it's accepted, when the team already thinks it's good enough.

@folkertdev

Copy link
Copy Markdown
Author

Right, this is the (final) ping for concerns to be raised. This was coordinated during the T-lang triage meeting.

This feature is based on the following lang proposal, it is basically unchanged from that thread.

Comment thread text/0000-extern-custom.md Outdated
Comment thread text/3980-extern-custom.md
@clarfonthey

Copy link
Copy Markdown
Contributor

I also felt a bit concerned by the sudden FCP, but the methodology here seems pretty canonical since it uses naked functions.

The only potential concern is bikeshedding the name "custom" which could potentially be worded as "none" (since this effectively is no ABI) but that's a pretty weak point and not worth blocking IMHO. Plus, it could be changed even post-acceptance but pre-stabilisation.

I see no reason to slow down on the FCP process.

@steffahn

steffahn commented Jul 2, 2026

Copy link
Copy Markdown
Member

Plus, it could be changed even post-acceptance but pre-stabilisation.

I would expect this time frame to be fairly short in this case.

@Lokathor

Lokathor commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

"none" is incorrect, as explained in the RFC, there is an ABI happening, it's just not an ABI the compiler knows how to use without assistance.

@clarfonthey

Copy link
Copy Markdown
Contributor

"none" is incorrect, as explained in the RFC, there is an ABI happening, it's just not an ABI the compiler knows how to use without assistance.

Yes, this is another reason justifying the choice, although I do think that "none" that the compiler knows about is still appropriate: the compiler is not using any ABI for the function, even though yes, technically, ABI will always exist no matter what. Even just jumping to a label is still an ABI, after all.

My point is that this is technically a weak point of contention, but not one I think is worth discussing here, since the name is more than adequately justified.

@Jules-Bertholet

Jules-Bertholet commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

and used in type checking of custom function pointers.

I'm skeptical of this. It only gives very partial type safety, because the signature doesn't tell you what the actual ABI is. I could imagine that the illusion of safety might cause more damage than it averts. It also makes it a breaking change to change the signature, which would otherwise be pure documentation (and therefore able to be improved at any time).

I think we should have only a single extern "any" fn(...) pointer type that can represent any signature, at least for now. The ecosystem can experiment with type safety via newtypes, and building it into the language can be revisited once we have a better idea of the use-cases and design space.

ehuss added 3 commits July 9, 2026 11:05
This updates section headers to use Markdown 2nd level headings. As part
of rust-lang#3883 we switched the template
to not use level-1 headings
@folkertdev

Copy link
Copy Markdown
Author

I'll echo that I'm skeptical of the actual benefits of allowing arbitrary signatures. The signature is a lie, if you need additional safety,you can wrap the type. But I'd happily implement allowing it, it does make the docs easier to write.

@joshtriplett @scottmcm given Jules' comment, do you see reason to re-evaluate your decision or is that just what T-lang decided and hence what we're going with?

Also to clarify

  • the current implementation allows ! as a return type, because it indicates divergence (an effect) which does seem useful
  • your notes about the signature say nothing about unsafe right? i.e. we will continue to require unsafe extern "custom" fn

@Jules-Bertholet

Copy link
Copy Markdown
Contributor

To clarify, my comment was only about function pointers. I don't object to allowing any signature on the method declaration, though I also think it would be fine to leave it as a future possibility

@rust-rfcbot rust-rfcbot added finished-final-comment-period The final comment period is finished for this RFC. to-announce and removed final-comment-period Will be merged/postponed/closed in ~10 calendar days unless new substational objections are raised. labels Jul 11, 2026
@rust-rfcbot

Copy link
Copy Markdown
Collaborator

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

@clarfonthey

Copy link
Copy Markdown
Contributor

A little uncomfortable that not only an FCP here, but an FCP in the main repo to stabilise both passed while there still seem to be a few active discussions. I don't think we need to block stabilisation on another FCP but I think we should at least address all the feedback on the RFC before merging the feature into stable.

@folkertdev

Copy link
Copy Markdown
Author

We discussed this again in the T-lang meeting on July 22nd (see notes), deciding to reject argument and return types, but to note that they can be a future extension.

Waffle (in DMs) requested that we don't special-case ! here. Like any other return type, it is purely documentation and can go out of sync with the implementation. Looking at the implementation and comments from the initial design again, I don't think that including -> ! was all that deliberate, but rather a result of the shared logic with the extern "interrupt-*" calling conventions. The PR linked below removes support for -> !, and I've added allowing specifically ! as a return type as a future extension.

Finally, I've added function pointer checks in rust-lang/rust#159780 and updated the text to reflect that we do enforce the restrictions (must be unsafe, no argument and return types) everywhere, including function pointer types.

With that, I believe the RFC text matches the current consensus of T-lang and friends, and can be merged. We can then let the dust settle a bit, and move forward with the stabilization PR in a couple of weeks.

I understand that there are some people in the thread here that would like to e.g. see arguments: that door is not closed. It just doesn't seem needed right now. If someone feels they have a compelling use case after stabilization of this minimal version, they can pick up the future extensions.

jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 24, 2026
…ptrs, r=WaffleLapkin

check `extern "custom"` function pointers

tracking issue: rust-lang#140829
related RFC: rust-lang/rfcs#3980

Best reviewed commit-by-commit.

This PR makes 3 changes

- extend the ABI checks we already performed on function definitions and trait and foreign declarations to function pointer types. This touches the various `interupt` ABIs and `extern "custom"`.
- remove the ability for `extern "custom"` to return `!`
- improve the suggestion when `safe` is used in a function pointer type
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 24, 2026
…ptrs, r=WaffleLapkin

check `extern "custom"` function pointers

tracking issue: rust-lang#140829
related RFC: rust-lang/rfcs#3980

Best reviewed commit-by-commit.

This PR makes 3 changes

- extend the ABI checks we already performed on function definitions and trait and foreign declarations to function pointer types. This touches the various `interupt` ABIs and `extern "custom"`.
- remove the ability for `extern "custom"` to return `!`
- improve the suggestion when `safe` is used in a function pointer type
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 25, 2026
…ptrs, r=WaffleLapkin

check `extern "custom"` function pointers

tracking issue: rust-lang#140829
related RFC: rust-lang/rfcs#3980

Best reviewed commit-by-commit.

This PR makes 3 changes

- extend the ABI checks we already performed on function definitions and trait and foreign declarations to function pointer types. This touches the various `interupt` ABIs and `extern "custom"`.
- remove the ability for `extern "custom"` to return `!`
- improve the suggestion when `safe` is used in a function pointer type
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 25, 2026
…ptrs, r=WaffleLapkin

check `extern "custom"` function pointers

tracking issue: rust-lang#140829
related RFC: rust-lang/rfcs#3980

Best reviewed commit-by-commit.

This PR makes 3 changes

- extend the ABI checks we already performed on function definitions and trait and foreign declarations to function pointer types. This touches the various `interupt` ABIs and `extern "custom"`.
- remove the ability for `extern "custom"` to return `!`
- improve the suggestion when `safe` is used in a function pointer type
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 25, 2026
…ptrs, r=WaffleLapkin

check `extern "custom"` function pointers

tracking issue: rust-lang#140829
related RFC: rust-lang/rfcs#3980

Best reviewed commit-by-commit.

This PR makes 3 changes

- extend the ABI checks we already performed on function definitions and trait and foreign declarations to function pointer types. This touches the various `interupt` ABIs and `extern "custom"`.
- remove the ability for `extern "custom"` to return `!`
- improve the suggestion when `safe` is used in a function pointer type
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Jul 25, 2026
…ptrs, r=WaffleLapkin

check `extern "custom"` function pointers

tracking issue: rust-lang#140829
related RFC: rust-lang/rfcs#3980

Best reviewed commit-by-commit.

This PR makes 3 changes

- extend the ABI checks we already performed on function definitions and trait and foreign declarations to function pointer types. This touches the various `interupt` ABIs and `extern "custom"`.
- remove the ability for `extern "custom"` to return `!`
- improve the suggestion when `safe` is used in a function pointer type
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Jul 25, 2026
…ptrs, r=WaffleLapkin

check `extern "custom"` function pointers

tracking issue: rust-lang#140829
related RFC: rust-lang/rfcs#3980

Best reviewed commit-by-commit.

This PR makes 3 changes

- extend the ABI checks we already performed on function definitions and trait and foreign declarations to function pointer types. This touches the various `interupt` ABIs and `extern "custom"`.
- remove the ability for `extern "custom"` to return `!`
- improve the suggestion when `safe` is used in a function pointer type
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 25, 2026
…ptrs, r=WaffleLapkin

check `extern "custom"` function pointers

tracking issue: rust-lang#140829
related RFC: rust-lang/rfcs#3980

Best reviewed commit-by-commit.

This PR makes 3 changes

- extend the ABI checks we already performed on function definitions and trait and foreign declarations to function pointer types. This touches the various `interupt` ABIs and `extern "custom"`.
- remove the ability for `extern "custom"` to return `!`
- improve the suggestion when `safe` is used in a function pointer type
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 25, 2026
…ptrs, r=WaffleLapkin

check `extern "custom"` function pointers

tracking issue: rust-lang#140829
related RFC: rust-lang/rfcs#3980

Best reviewed commit-by-commit.

This PR makes 3 changes

- extend the ABI checks we already performed on function definitions and trait and foreign declarations to function pointer types. This touches the various `interupt` ABIs and `extern "custom"`.
- remove the ability for `extern "custom"` to return `!`
- improve the suggestion when `safe` is used in a function pointer type
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 26, 2026
…ptrs, r=WaffleLapkin

check `extern "custom"` function pointers

tracking issue: rust-lang#140829
related RFC: rust-lang/rfcs#3980

Best reviewed commit-by-commit.

This PR makes 3 changes

- extend the ABI checks we already performed on function definitions and trait and foreign declarations to function pointer types. This touches the various `interupt` ABIs and `extern "custom"`.
- remove the ability for `extern "custom"` to return `!`
- improve the suggestion when `safe` is used in a function pointer type
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 26, 2026
…ptrs, r=WaffleLapkin

check `extern "custom"` function pointers

tracking issue: rust-lang#140829
related RFC: rust-lang/rfcs#3980

Best reviewed commit-by-commit.

This PR makes 3 changes

- extend the ABI checks we already performed on function definitions and trait and foreign declarations to function pointer types. This touches the various `interupt` ABIs and `extern "custom"`.
- remove the ability for `extern "custom"` to return `!`
- improve the suggestion when `safe` is used in a function pointer type
rust-timer added a commit to rust-lang/rust that referenced this pull request Jul 26, 2026
Rollup merge of #159780 - folkertdev:extern-custom-check-fn-ptrs, r=WaffleLapkin

check `extern "custom"` function pointers

tracking issue: #140829
related RFC: rust-lang/rfcs#3980

Best reviewed commit-by-commit.

This PR makes 3 changes

- extend the ABI checks we already performed on function definitions and trait and foreign declarations to function pointer types. This touches the various `interupt` ABIs and `extern "custom"`.
- remove the ability for `extern "custom"` to return `!`
- improve the suggestion when `safe` is used in a function pointer type
pull Bot pushed a commit to xtqqczze/rust-lang-miri that referenced this pull request Jul 27, 2026
…affleLapkin

check `extern "custom"` function pointers

tracking issue: rust-lang/rust#140829
related RFC: rust-lang/rfcs#3980

Best reviewed commit-by-commit.

This PR makes 3 changes

- extend the ABI checks we already performed on function definitions and trait and foreign declarations to function pointer types. This touches the various `interupt` ABIs and `extern "custom"`.
- remove the ability for `extern "custom"` to return `!`
- improve the suggestion when `safe` is used in a function pointer type
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

disposition-merge This RFC is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this RFC. I-lang-radar Items that are on lang's radar and will need eventual work or consideration. T-lang Relevant to the language team, which will review and decide on the RFC. to-announce

Projects

None yet

Development

Successfully merging this pull request may close these issues.