2021-04-10 05:09:10 -05:00
|
|
|
// This should fail even without validation, but some MIR opts mask the error
|
2022-07-08 11:08:32 -05:00
|
|
|
//@compile-flags: -Zmiri-disable-validation -Zmir-opt-level=0
|
2021-04-10 05:09:10 -05:00
|
|
|
|
|
|
|
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 ";"!
|
2022-07-11 06:44:55 -05:00
|
|
|
let val = *x; //~ ERROR: dereferenced after this allocation got freed
|
2021-04-10 05:09:10 -05:00
|
|
|
println!("{}", val);
|
|
|
|
}
|
|
|
|
}
|