-
Notifications
You must be signed in to change notification settings - Fork 355
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #1766 - RalfJung:dropped-temporary, r=RalfJung
add test to detect dropped temporary Let's make sure we catch this kind of error.
- Loading branch information
Showing
2 changed files
with
14 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// This should fail even without validation, but some MIR opts mask the error | ||
// compile-flags: -Zmiri-disable-validation -Zmir-opt-level=0 | ||
|
||
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 dereferenced after this allocation got freed | ||
println!("{}", val); | ||
} | ||
} |
File renamed without changes.