2019-02-15 19:43:56 -06:00
|
|
|
// A callee may not write to the destination of our `&mut` without us noticing.
|
2018-10-29 13:48:43 -05:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let mut x = 15;
|
|
|
|
let xraw = &mut x as *mut _;
|
2019-02-15 19:43:56 -06:00
|
|
|
// Derived from raw value, so using raw value is still ok ...
|
|
|
|
let xref = unsafe { &mut *xraw };
|
2018-10-29 13:48:43 -05:00
|
|
|
callee(xraw);
|
2019-02-15 19:43:56 -06:00
|
|
|
// ... though any use of raw value will invalidate our ref.
|
|
|
|
let _val = *xref;
|
2019-02-12 03:51:03 -06:00
|
|
|
//~^ ERROR: does not exist on the borrow stack
|
2018-10-29 13:48:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn callee(xraw: *mut i32) {
|
|
|
|
unsafe { *xraw = 15 };
|
|
|
|
}
|