rust/tests/compile-fail-fullmir/stacked_borrows/illegal_read1.rs
2018-11-16 10:01:54 +01:00

16 lines
434 B
Rust

// 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 _;
let xref = unsafe { &mut *xraw }; // derived from raw, so using raw is still okay...
callee(xraw);
let _val = *xref; // ...but any use of raw will invalidate our ref.
//~^ ERROR: does not exist on the stack
}
fn callee(xraw: *mut i32) {
let _val = unsafe { *xraw };
}