2018-10-29 13:48:43 -05:00
|
|
|
// A callee may not read the destination of our `&mut` without
|
|
|
|
// us noticing.
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let mut x = 15;
|
|
|
|
let xraw = &mut x as *mut _;
|
2019-02-15 19:43:56 -06:00
|
|
|
let xref = unsafe { &mut *xraw }; // derived from raw, so using raw is still ok...
|
2018-10-29 13:48:43 -05:00
|
|
|
callee(xraw);
|
|
|
|
let _val = *xref; // ...but any use of raw will invalidate our ref.
|
2019-04-16 10:17:28 -05:00
|
|
|
//~^ ERROR: borrow stack
|
2018-10-29 13:48:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn callee(xraw: *mut i32) {
|
|
|
|
let _val = unsafe { *xraw };
|
|
|
|
}
|