Skip to content

Tracking issue for const extern fn and const unsafe extern fn #64926

Closed
@Aaron1011

Description

@Aaron1011

This is a tracking issue for implementing and stabilizing defining a const extern fn and const unsafe extern fn

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

  1. 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
  2. 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

No one assigned

    Labels

    A-FFIArea: Foreign function interface (FFI)A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)B-unstableBlocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCF-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 PRT-langRelevant to the language team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions