Closed
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)
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
Metadata
Metadata
Assignees
Labels
Area: Foreign function interface (FFI)Area: Constant evaluation, covers all const contexts (static, const fn, ...)Blocker: Implemented in the nightly compiler and unstable.Category: An issue tracking the progress of sth. like the implementation of an RFC`#![feature(const_extern_fn)]`Status: This is ready to stabilize; it may need a stabilization report and a PRRelevant to the language team, which will review and decide on the PR/issue.