]> git.lizzy.rs Git - rust.git/blob - src/tools/miri/tests/fail/stacked_borrows/illegal_read_despite_exposed2.rs
Rollup merge of #102589 - RalfJung:scoped-threads-dangling, r=m-ou-se
[rust.git] / src / tools / miri / tests / fail / stacked_borrows / illegal_read_despite_exposed2.rs
1 //@compile-flags: -Zmiri-permissive-provenance
2
3 fn main() {
4     unsafe {
5         let root = &mut 42;
6         let addr = root as *mut i32 as usize;
7         let exposed_ptr = addr as *mut i32;
8         // From the exposed ptr, we get a new unique ptr.
9         let root2 = &mut *exposed_ptr;
10         // let _fool = root2 as *mut _; // this would fool us, since SRW(N+1) remains on the stack
11         // Stack: Unknown(<N), Unique(N)
12         // Stack if _fool existed: Unknown(<N), Unique(N), SRW(N+1)
13         // And we test that it has uniqueness by doing a conflicting read.
14         let _val = *exposed_ptr;
15         // Stack: Unknown(<N), Disabled(N)
16         // collapsed to Unknown(<N)
17         // Stack if _fool existed: Unknown(<N), Disabled(N), SRW(N+1); collapsed to Unknown(<N+2) which would not cause an ERROR
18         let _val = *root2; //~ ERROR: /read access .* tag does not exist in the borrow stack/
19     }
20 }