It's only dangerous if you can also make the reverse cast, right? From ints to function pointers. Does Rust also allow that in safe code?
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/fu...
In other words `0usize as fn ()` is insta-undefined behavior, and you can't have that in safe code.
The broader topic of whether it is safe, or wise, to cast between pointers and integers in general is an area of active research. Ralf Jung's blog is required reading on this topic: https://www.ralfj.de/blog/2022/04/11/provenance-exposed.html