[Pre-RFC] Make some feature-detected function-to-fn-pointer casts safe through ZST token types
Rust Internals [Unofficial]
May 25, 2026
Doing a function pointer cast seems to me like a very direct way to do multi-version dispatch.
Would it be any easier to implement if the cast didn't use ZST's but was just a macro? There's already is_x86_feature_detected so the main thing would be checking the target_feature on the passed method (which I suppose probably isn't known until after macro expansion but may that's solvable?)
#[target_feature(enable = "sse4.1")]
fn crazy() {
…
}
fn boring_scalar_implementation() {
…
}
fn choose_implementation() -> ... {
let sse_impl: Option<_> = try_target_feature_cast!("sse4.1", crazy);
see_impl.unwrap_or(boring_scalar_implementation)
}
Discussion in the ATmosphere