rust/tests/compile-fail/box-cell-alias.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

19 lines
502 B
Rust

// compile-flags: -Zmiri-tag-raw-pointers
// Taken from <https://github.com/rust-lang/unsafe-code-guidelines/issues/194#issuecomment-520934222>.
use std::cell::Cell;
fn helper(val: Box<Cell<u8>>, ptr: *const Cell<u8>) -> u8 {
val.set(10);
unsafe { (*ptr).set(20); } //~ ERROR does not exist in the borrow stack
val.get()
}
fn main() {
let val: Box<Cell<u8>> = Box::new(Cell::new(25));
let ptr: *const Cell<u8> = &*val;
let res = helper(val, ptr);
assert_eq!(res, 20);
}