rust/tests/fail/stacked_borrows/illegal_read6.rs
2022-07-11 11:48:56 +00:00

11 lines
309 B
Rust

// Creating a shared reference does not leak the data to raw pointers.
fn main() {
unsafe {
let x = &mut 0;
let raw = x as *mut _;
let x = &mut *x; // kill `raw`
let _y = &*x; // this should not activate `raw` again
let _val = *raw; //~ ERROR: borrow stack
}
}