Closed
Description
The program below creates a promoted in a constant via
&unsafe { BoolTransmute { val: 3 }.bl }
but immediately casts this to a raw pointer. Now having weird values behind raw pointers is fine, but we have an intermediate reference to an invalid value. I don't understand how this compiles considering that the promoted is essentially
static PROMOTED: bool = transmute(3u8);
Apparently we don't validate promoteds. I think we are allowed to fix this and validate promoteds, even though it will be a breaking change, because the user had to create an intermediate reference that pointed to an invalid bool.
cc @RalfJung
union BoolTransmute {
val: u8,
bl: bool,
}
const RAW_TRAIT_OBJ_CONTENT_INVALID: *const dyn Trait = &unsafe { BoolTransmute { val: 3 }.bl } as *const _;
trait Trait {}
impl Trait for bool {}