Add support for const unsafe? extern fn by Aaron1011 · Pull Request #64906 · rust-lang/rust (original) (raw)

This works just as you might expect - an const extern fn is a const fn that is callable from foreign code.

Currently, panicking is not allowed in consts. When rust-lang/rfcs#2345 (#51999) is stabilized, then panicking in an const extern fn will produce a compile-time error when invoked at compile time, and an abort when invoked at runtime.

Since this is extending the language (we're allowing the const keyword in a new context), I believe that this will need an FCP. However, it's a very minor change, so I didn't think that filing an RFC was necessary.

This will allow libc (and other FFI crates) to make many functions const, without having to give up on making them extern as well.

Tracking issue: #64926.