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

11 lines
330 B
Rust
Raw Normal View History

// 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 shared reference with non-reactivatable tag: Location should be frozen
}