Closed
Description
Consider the following code:
const DST: &[u8] = unsafe { std::mem::transmute(1usize) };
fn main() {
match &b""[..] {
DST => {}
}
}
This code hits a peculiar code path in the interpreter:
rust/compiler/rustc_mir/src/interpret/place.rs
Lines 916 to 927 in 30e49a9
This code path should be unreachable: just like the interpreter can assume that code code it runs on is well-typed, it should be able to assume that the code it runs on has its transmutes checked. But something seems to be different about transmute
when compared with "normal" type-checking.
TransmuteSizeDiff
is a hack; we should instead arrange things in a way that failing the transmute check inhibits const-evaluation the same way that true + 4
inhibitis const-evaluation.