about summary refs log tree commit diff
path: root/src/tools/miri/tests/fail/dangling_pointers/stack_temporary.rs
blob: 5f8a1988b3c1034fe297b87ec18ba0dd32cc06ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// This should fail even without validation
//@compile-flags: -Zmiri-disable-validation

unsafe fn make_ref<'a>(x: *mut i32) -> &'a mut i32 {
    &mut *x
}

fn main() {
    unsafe {
        let x = make_ref(&mut 0); // The temporary storing "0" is deallocated at the ";"!
        let val = *x; //~ ERROR: has been freed
        println!("{}", val);
    }
}