rust/tests/fail/validity/dangling_ref3.rs
2022-07-11 11:48:56 +00:00

13 lines
307 B
Rust

// Make sure we catch this even without Stacked Borrows
//@compile-flags: -Zmiri-disable-stacked-borrows
use std::mem;
fn dangling() -> *const u8 {
let x = 0u8;
&x as *const _
}
fn main() {
let _x: &i32 = unsafe { mem::transmute(dangling()) }; //~ ERROR: dangling reference (use-after-free)
}