rust/tests/compile-fail/validity/transmute_through_ptr.rs
2018-12-02 11:26:09 +01:00

15 lines
359 B
Rust

#[repr(u32)]
enum Bool { True }
fn evil(x: &mut Bool) {
let x = x as *mut _ as *mut u32;
unsafe { *x = 44; } // out-of-bounds enum discriminant
}
fn main() {
let mut x = Bool::True;
evil(&mut x);
let _y = x; // reading this ought to be enough to trigger validation
//~^ ERROR encountered 44, but expected a valid enum discriminant
}