rust/tests/compile-fail/stacked_borrows/pass_invalid_shr.rs

11 lines
327 B
Rust

// Make sure that we cannot pass by argument a `&` that got already invalidated.
fn foo(_: &i32) {}
fn main() {
let x = &mut 42;
let xraw = &*x as *const _;
let xref = unsafe { &*xraw };
*x = 42; // invalidate xraw
foo(xref); //~ ERROR Shr reference with non-reactivatable tag: Location should be frozen
}