Description
It is a fairly commonplace mistake to do a transmute::<T, U>
for T
and U
which are not necessarily compatible, but happen to work at that some particular point in time. These transmutes either change in behaviour when the compiler is updated or stop compiling altogether (because the size of T and size of U are not the same anymore (see e.g. #50830)).
The same way we error for mismatching sizes, we can also raise such an error (possibly disable-able by a #[feature(very_fast_such_dangerous)]
) for types for which sizes may change over time with future compiler releases. Namely, this would prevent using transmute
on stable for anything that
- Does not have one of the whitelisted
#[repr()]
attribute on top of the type declaration; - Is not a FFI-safe type in the first place.
If we did that already, the issue linked before would’ve failed, because none of the enums have a #[repr]
attribute on top of them, making their layout unspecified and therefore not transmutable.