rust/tests/compile-fail/stacked_borrows/illegal_write5.rs
Ralf Jung ef52be031c adjust compile-fail error messages
This also passes miri-test-libstd!
2019-04-17 16:02:57 +02:00

17 lines
443 B
Rust

// A callee may not write to the destination of our `&mut` without us noticing.
fn main() {
let mut x = 15;
let xraw = &mut x as *mut _;
// Derived from raw value, so using raw value is still ok ...
let xref = unsafe { &mut *xraw };
callee(xraw);
// ... though any use of raw value will invalidate our ref.
let _val = *xref;
//~^ ERROR: borrow stack
}
fn callee(xraw: *mut i32) {
unsafe { *xraw = 15 };
}