2018-11-09 03:53:28 -06:00
|
|
|
// We *can* have aliasing &RefCell<T> and &mut T, but we cannot read through the former.
|
|
|
|
// Else we couldn't optimize based on the assumption that `xref` below is truly unique.
|
2022-03-17 08:49:10 -05:00
|
|
|
// normalize-stderr-test: "0x[0-9a-fA-F]+" -> "$$HEX"
|
2018-11-09 03:53:28 -06:00
|
|
|
|
|
|
|
use std::cell::RefCell;
|
|
|
|
use std::{mem, ptr};
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let rc = RefCell::new(0);
|
|
|
|
let mut refmut = rc.borrow_mut();
|
|
|
|
let xref: &mut i32 = &mut *refmut;
|
2019-02-15 19:43:56 -06:00
|
|
|
let xshr = &rc; // creating this is ok
|
2018-11-09 03:53:28 -06:00
|
|
|
let _val = *xref; // we can even still use our mutable reference
|
|
|
|
mem::forget(unsafe { ptr::read(xshr) }); // but after reading through the shared ref
|
|
|
|
let _val = *xref; // the mutable one is dead and gone
|
2019-04-16 10:17:28 -05:00
|
|
|
//~^ ERROR borrow stack
|
2018-11-09 03:53:28 -06:00
|
|
|
}
|