rust/tests/compile-fail/stacked_borrows/illegal_read1.rs

16 lines
417 B
Rust
Raw Normal View History

// 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...
callee(xraw);
let _val = *xref; // ...but any use of raw will invalidate our ref.
//~^ ERROR: borrow stack
}
fn callee(xraw: *mut i32) {
let _val = unsafe { *xraw };
}