rust/tests/compile-fail/stacked_borrows/raw_tracking.rs
Ben Kimock 730cd27248 Print more in SB error diagnostics
This tries to clarify exactly why an access is not valid by printing
what memory range the access was over, which in combination with
tag-tracking may help a user figure out the source of the problem.
2022-03-16 20:12:04 -04:00

13 lines
519 B
Rust

// compile-flags: -Zmiri-tag-raw-pointers
//! This demonstrates a provenance problem that requires tracking of raw pointers to be detected.
fn main() {
let mut l = 13;
let raw1 = &mut l as *mut _;
let raw2 = &mut l as *mut _; // invalidates raw1
// Without raw pointer tracking, Stacked Borrows cannot distinguish raw1 and raw2, and thus
// fails to realize that raw1 should not be used any more.
unsafe { *raw1 = 13; } //~ ERROR does not exist in the borrow stack
unsafe { *raw2 = 13; }
}