I believe it is always sound (for any T: Sized
) to cast/transmute from *const T
/*mut T
to an unsafe
function pointer... unless we emit metadata that fn()
pointers are valid function pointers, which tbh sounds familiar.
Still, I think it would be reasonable to allow as
to cast from pointers-to-sized-T
to function pointers in unsafe
contexts. Currently any use case that type-erases function pointers is required to mem::transmute
to get the type back. This is still just a pointer cast, though, so it seems reasonable to be done with as
. What do you think?
(Counterargument: *const T
to &T
is "just a pointer cast," but cannot be done with as
, requiring a prefix &*
. Counter-counterargument: maybe it should be possible with as
, to remove the pingpong control flow of &*(ptr as *const _)
?)