rust/tests/compile-fail/stacked_borrows/shr_frozen_violation1.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

14 lines
261 B
Rust

fn foo(x: &mut i32) -> i32 {
*x = 5;
unknown_code(&*x);
*x // must return 5
}
fn main() {
println!("{}", foo(&mut 0));
}
fn unknown_code(x: &i32) {
unsafe { *(x as *const i32 as *mut i32) = 7; } //~ ERROR only grants SharedReadOnly permission
}