rust/tests/fail/stacked_borrows/illegal_write5.rs

17 lines
486 B
Rust
Raw Normal View History

2019-02-15 19:43:56 -06:00
// 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 _;
2019-02-15 19:43:56 -06:00
// Derived from raw value, so using raw value is still ok ...
let xref = unsafe { &mut *xraw };
callee(xraw);
2019-02-15 19:43:56 -06:00
// ... though any use of raw value will invalidate our ref.
let _val = *xref;
2022-07-13 17:59:33 -05:00
//~^ ERROR: /read access .* tag does not exist in the borrow stack/
}
fn callee(xraw: *mut i32) {
unsafe { *xraw = 15 };
}