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

11 lines
351 B
Rust
Raw Normal View History

2019-05-15 10:23:26 -05:00
use std::cell::UnsafeCell;
fn main() { unsafe {
let c = &UnsafeCell::new(UnsafeCell::new(0));
let inner_uniq = &mut *c.get();
let inner_shr = &*inner_uniq; // a SharedRW with a tag
*c.get() = UnsafeCell::new(1); // invalidates the SharedRW
let _val = *inner_shr.get(); //~ ERROR borrow stack
let _val = *inner_uniq.get();
} }