about summary refs log tree commit diff
path: root/src/tools/miri/tests/fail/validity/dangling_ref3.rs
blob: 0fecd8f1c285fbbeeddbb997d082cc448c49db78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// Make sure we catch this even without Stacked Borrows
//@compile-flags: -Zmiri-disable-stacked-borrows

#![allow(dangling_pointers_from_locals)]

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)
}