[Pre-RFC] Make some feature-detected function-to-fn-pointer casts safe through ZST token types
Rust Internals [Unofficial]
May 24, 2026
ais523:
A possible alternative: give the ZST tokens themselves a method that casts from function item to function pointer.
I would strongly prefer that, or some other variant that explicitly requires the token to be named. Having the mere presence of an unmentioned local variable in scope unlock further operations seems way too implicit to me.
Also note that we already have something kind of similar:
#[target_feature(enable = "avx2")]
fn fun_with_avx2() {}
#[target_feature(enable = "avx2")]
fn make_fn_ptr() -> fn() {
fun_with_avx2
}
If the current function has a target feature enabled, it can coerce other function items with that target feature to safe function pointers.
Is there a way to use this to achieve what you are looking for?
Discussion in the ATmosphere