]> git.lizzy.rs Git - rust.git/blob - src/tools/miri/tests/fail/dangling_pointers/stack_temporary.rs
Rollup merge of #102127 - TaKO8Ki:use-appropriate-variable-names, r=lcnr
[rust.git] / src / tools / miri / tests / fail / dangling_pointers / stack_temporary.rs
1 // This should fail even without validation, but some MIR opts mask the error
2 //@compile-flags: -Zmiri-disable-validation -Zmir-opt-level=0
3
4 unsafe fn make_ref<'a>(x: *mut i32) -> &'a mut i32 {
5     &mut *x
6 }
7
8 fn main() {
9     unsafe {
10         let x = make_ref(&mut 0); // The temporary storing "0" is deallocated at the ";"!
11         let val = *x; //~ ERROR: dereferenced after this allocation got freed
12         println!("{}", val);
13     }
14 }