]> git.lizzy.rs Git - rust.git/blob - tests/compile-fail/stacked_borrows/illegal_read1.rs
3fb38abefdae483b2febb7e0f5706cd6397d072a
[rust.git] / tests / compile-fail / stacked_borrows / illegal_read1.rs
1 // A callee may not read the destination of our `&mut` without
2 // us noticing.
3
4 fn main() {
5     let mut x = 15;
6     let xraw = &mut x as *mut _;
7     let xref = unsafe { &mut *xraw }; // derived from raw, so using raw is still ok...
8     callee(xraw);
9     let _val = *xref; // ...but any use of raw will invalidate our ref.
10     //~^ ERROR: does not exist on the borrow stack
11 }
12
13 fn callee(xraw: *mut i32) {
14     let _val = unsafe { *xraw };
15 }