rust/tests/compile-fail/cast_box_int_to_fn_ptr.rs

13 lines
341 B
Rust

// Validation makes this fail in the wrong place
// compile-flags: -Zmir-emit-validate=0
fn main() {
let b = Box::new(42);
let g = unsafe {
std::mem::transmute::<&usize, &fn(i32)>(&b)
};
(*g)(42) //~ ERROR constant evaluation error [E0080]
//~^ NOTE a memory access tried to interpret some bytes as a pointer
}