]> git.lizzy.rs Git - rust.git/blob - src/tools/miri/tests/fail/stacked_borrows/disable_mut_does_not_merge_srw.rs
Reintroduce the span printing in miri (plus point to spans where possible)
[rust.git] / src / tools / miri / tests / fail / stacked_borrows / disable_mut_does_not_merge_srw.rs
1 // This tests demonstrates the effect of 'Disabling' mutable references on reads, rather than
2 // removing them from the stack -- the latter would 'merge' neighboring SRW groups which we would
3 // like to avoid.
4 fn main() {
5     unsafe {
6         let mut mem = 0;
7         let base = &mut mem as *mut i32; // the base pointer we build the rest of the stack on
8         let raw = {
9             let mutref = &mut *base;
10             mutref as *mut i32
11         };
12         // In the stack, we now have [base, mutref, raw].
13         // We do this in a weird way where `mutref` is out of scope here, just in case
14         // Miri decides to get smart and argue that items for tags that are no longer
15         // used by any pointer stored anywhere in the machine can be removed.
16         let _val = *base;
17         // now mutref is disabled
18         *base = 1;
19         // this should pop raw from the stack, since it is in a different SRW group
20         let _val = *raw; //~ERROR: that tag does not exist in the borrow stack
21     }
22 }