Skip to content

Commit

Permalink
defend test against overly smart Miri
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Aug 16, 2022
1 parent 2e3da5d commit db43ee5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
11 changes: 8 additions & 3 deletions tests/fail/stacked_borrows/disable_mut_does_not_merge_srw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ fn main() {
unsafe {
let mut mem = 0;
let base = &mut mem as *mut i32; // the base pointer we build the rest of the stack on
let mutref = &mut *base;
let raw = mutref as *mut i32;
// in the stack, we now have [base, mutref, raw]
let raw = {
let mutref = &mut *base;
mutref as *mut i32
};
// In the stack, we now have [base, mutref, raw].
// We do this in a weird way where `mutref` is out of scope here, just in case
// Miri decides to get smart and argue that items for tags that are no longer
// used by any pointer stored anywhere in the machine can be removed.
let _val = *base;
// now mutref is disabled
*base = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ LL | let _val = *raw;
help: <TAG> was created by a retag at offsets [0x0..0x4]
--> $DIR/disable_mut_does_not_merge_srw.rs:LL:CC
|
LL | let raw = mutref as *mut i32;
| ^^^^^^
LL | mutref as *mut i32
| ^^^^^^
help: <TAG> was later invalidated at offsets [0x0..0x4]
--> $DIR/disable_mut_does_not_merge_srw.rs:LL:CC
|
Expand Down

0 comments on commit db43ee5

Please sign in to comment.