]> git.lizzy.rs Git - rust.git/blob - src/tools/miri/tests/fail/stacked_borrows/pointer_smuggling.rs
Auto merge of #102169 - scottmcm:constify-some-conditions, r=thomcc
[rust.git] / src / tools / miri / tests / fail / stacked_borrows / pointer_smuggling.rs
1 static mut PTR: *mut u8 = 0 as *mut _;
2
3 fn fun1(x: &mut u8) {
4     unsafe {
5         PTR = x;
6     }
7 }
8
9 fn fun2() {
10     // Now we use a pointer we are not allowed to use
11     let _x = unsafe { *PTR }; //~ ERROR: /read access .* tag does not exist in the borrow stack/
12 }
13
14 fn main() {
15     let mut val = 0;
16     let val = &mut val;
17     fun1(val);
18     *val = 2; // this invalidates any raw ptrs `fun1` might have created.
19     fun2(); // if they now use a raw ptr they break our reference
20 }