-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-FFIArea: Foreign function interface (FFI)Area: Foreign function interface (FFI)A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCF-const_extern_fn`#![feature(const_extern_fn)]``#![feature(const_extern_fn)]`S-tracking-ready-to-stabilizeStatus: This is ready to stabilize; it may need a stabilization report and a PRStatus: This is ready to stabilize; it may need a stabilization report and a PRT-langRelevant to the language teamRelevant to the language team
Description
This is a tracking issue for implementing and stabilizing defining a const extern fn
and const unsafe extern fn
- Add a test according to Add support for
const unsafe? extern fn
#64906 (comment) (added in Ensure that we error when calling "const extern fn" with wrong convention #68370)To pick up a draggable item, press the space bar. While dragging, use the arrow keys to move the item. Press space again to drop the item in its new position, or press escape to cancel.
Stabilizaton Report
Summary
This allows writing const unsafe extern "calling-convention" fn
and const extern "calling-convention" fn
:
Today Rust and C calling conventions are stable (as of 1.62, see #95346). All other calling conventions are still unstable.
const extern fn foo1(val: u8) -> u8 { val + 1 }
const extern "C" fn foo2(val: u8) -> u8 { val + 1}
const unsafe extern fn bar1(val: bool) -> bool { !val }
const unsafe extern "C" fn bar2(val: bool) -> bool { !val }
This can be used to const-ify an extern fn
(or equivalently, to make a const fn
callable from external code).
Test cases
- Test for defining and calling in Rust code: https://github.com/rust-lang/rust/blob/master/src/test/ui/consts/const-extern-fn/const-extern-fn.rs
- Test that calling with the wrong calling convention (from a
const
context) leads to an error: https://github.com/rust-lang/rust/blob/master/src/test/ui/consts/miri_unleashed/abi-mismatch.rs
stepancheg, GrayJack, Snowiiii and CGMossadignifiedquire and CGMossadignifiedquire and CGMossa
Metadata
Metadata
Assignees
Labels
A-FFIArea: Foreign function interface (FFI)Area: Foreign function interface (FFI)A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCF-const_extern_fn`#![feature(const_extern_fn)]``#![feature(const_extern_fn)]`S-tracking-ready-to-stabilizeStatus: This is ready to stabilize; it may need a stabilization report and a PRStatus: This is ready to stabilize; it may need a stabilization report and a PRT-langRelevant to the language teamRelevant to the language team
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
const fn
#57563const unsafe? extern fn
#64906RalfJung commentedon Oct 1, 2019
Could you explain a bit more what this means and what the point is? What does the bare
extern
keyword even do?extern "Rust" fn
andfn
are the same thing, after all. (extern fn
is poorly named; AFAIK it really is about specifying the ABI and has little to do with extern visibility.)Aaron1011 commentedon Oct 1, 2019
@RalfJung: The point is to be able to define an
const extern fn
(i.e.const extern "C" fn
), which has a C-compatible ABI and can be invoked from const contexts.Rollup merge of rust-lang#64906 - Aaron1011:feature/extern-const-fn, …
Centril commentedon Oct 7, 2019
Implemented in #64906 (2019-10-07).
44 remaining items
joshtriplett commentedon Jun 22, 2022
It looks like "C" and "Rust" calling conventions were stabilized for the upcoming 1.62 release.
Other calling conventions could be stabilized as well; is there a blocker for doing so?
RalfJung commentedon Jun 22, 2022
I am not aware of any calling convention being special here. (Other than variadics, but those are generally unstable, not just for
const fn
.)const extern fn
definitions are unstable. jyao1/rust-spdm#260const_extern_fn
#129753const_extern_fn
rust-lang/reference#1596Auto merge of rust-lang#129753 - folkertdev:stabilize-const-extern-fn…
Auto merge of #129753 - folkertdev:stabilize-const-extern-fn, r=RalfJung