Value validity for the unsafe fn type?
⚓ Rust 📅 2026-02-20 👤 surdeus 👁️ 1So in The Reference, I can't really find information regarding whether [...] fn([...]) [-> ...] has to reference a function callable with the given signature and ABI. We know behavior allowed by safe rust will try to be safe in the future, so since safe function pointers (e.g. fn(T) -> U, extern "C" fn(T) -> U) are callable without unsafe blocks, they must have an invariant like str, Pin<T> or &T that they properly reference a function with correct signature. But the same line of reasoning cannot be applied to unsafe function pointers (e.g. unsafe fn(T) -> U, unsafe extern "C" fn(T) -> U) because they need to be called within unsafe blocks.
So are unsafe [...] fn([...]) [-> ...]s more like NonNull<T> or &T?
For now I am using a #[repr(C)] union to represent "probably dangling" function pointers
2 posts - 2 participants
🏷️ Rust_feed