rust/tests/pass/transmute_fat.rs
2022-06-20 23:50:40 -07:00

10 lines
391 B
Rust

// Stacked Borrows disallows this becuase the reference is never cast to a raw pointer.
// compile-flags: -Zmiri-disable-stacked-borrows
fn main() {
// If we are careful, we can exploit data layout...
let raw = unsafe { std::mem::transmute::<&[u8], [*const u8; 2]>(&[42]) };
let ptr: *const u8 = unsafe { std::mem::transmute_copy(&raw) };
assert_eq!(unsafe { *ptr }, 42);
}