]> git.lizzy.rs Git - rust.git/blob - src/tools/miri/tests/fail/stacked_borrows/illegal_read1.rs
Rollup merge of #104627 - calebzulawski:print-target-features, r=compiler-errors
[rust.git] / src / tools / miri / tests / fail / stacked_borrows / illegal_read1.rs
1 // A callee may not read the destination of our `&mut` without
2 // us noticing.
3
4 #[rustfmt::skip] // rustfmt bug: https://github.com/rust-lang/rustfmt/issues/5391
5 fn main() {
6     let mut x = 15;
7     let xraw = &mut x as *mut _;
8     let xref = unsafe { &mut *xraw }; // derived from raw, so using raw is still ok...
9     callee(xraw);
10     let _val = *xref; // ...but any use of raw will invalidate our ref.
11     //~^ ERROR: /read access .* tag does not exist in the borrow stack/
12 }
13
14 fn callee(xraw: *mut i32) {
15     let _val = unsafe { *xraw };
16 }