Hi. There is currently an open stabilization PR stabilize const_extern_fn
. Its tracking issue states that this feature:
This can be used to const-ify an
extern fn
(or equivalently, to make aconst fn
callable from external code).
However I don't understand what is the real practical benefit. If I want to make a const fn
callable from external code, then I could just simply do:
mod foo {
pub const fn foo() {}
}
#[no_mangle]
extern "C" fn foo() {
foo::foo()
}
The only worry here would be "will foo::foo be inlined?". But this should be pretty obvious to the compiler. Is saving one wrapper function the only benefit of this feature?
And on the other hand, what does "const-ifing an extern fn
" even mean? My understanding is that extern
functions are provided by the linker, and are totally opaque to the compiler. So how such function could be called in the const
context?