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

16 lines
491 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();
2019-05-21 08:41:26 -05:00
// stack: [c: SharedReadWrite, inner_uniq: Unique]
let inner_shr = &*inner_uniq; // adds a SharedReadWrite
// stack: [c: SharedReadWrite, inner_uniq: Unique, inner_shr: SharedReadWrite]
*c.get() = UnsafeCell::new(1); // invalidates inner_shr
// stack: [c: SharedReadWrite]
2019-05-15 10:23:26 -05:00
let _val = *inner_shr.get(); //~ ERROR borrow stack
} }