rust/tests/compile-fail/dangling_pointer_deref.rs

10 lines
248 B
Rust

fn main() {
let p = {
let b = Box::new(42);
&*b as *const i32
};
let x = unsafe { *p }; //~ ERROR constant evaluation error
//~^ NOTE dangling pointer was dereferenced
panic!("this should never print: {}", x);
}