rust/tests/compile-fail/stacked_borrows/interior_mut1.rs
2019-05-21 15:43:18 +02:00

16 lines
491 B
Rust

use std::cell::UnsafeCell;
fn main() { unsafe {
let c = &UnsafeCell::new(UnsafeCell::new(0));
let inner_uniq = &mut *c.get();
// 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]
let _val = *inner_shr.get(); //~ ERROR borrow stack
} }