3 ms·
It does not. Oddly enough, it doesn't even allow it in unsafe code, not with a normal cast. You have to use transmute. I believe this is due to concerns abou
by comex 2y ago
It does not.
Oddly enough, it doesn't even allow it in unsafe code, not with a normal cast. You have to use transmute. I believe this is due to concerns about targets where function and data pointers have different representations.
https://rust-lang.github.io/unsafe-code-guidelines/layout/function-pointers.html https://rust-lang.github.io/unsafe-code-guidelines/layout/fu...
- duped 2y agoI believe it has more to do with the fact that function pointers are effectively &'static T (static references) and references are forbidden from being null. But it's probably a bit of both. In other words `0usize as fn ()` is insta-undefined behavior, and you can't have that in safe code.