1 // A callee may not read the destination of our `&mut` without
2 // us noticing.
3 
main()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: borrow stack
11 }
12 
callee(xraw: *mut i32)13 fn callee(xraw: *mut i32) {
14     // We are a bit sneaky: We first create a shared ref, exploiting the reborrowing rules,
15     // and then we read through that.
16     let shr = unsafe { &*xraw };
17     let _val = *shr;
18 }
19