]> git.lizzy.rs Git - rust.git/blob - src/tools/miri/tests/fail/stacked_borrows/illegal_read5.rs
Rollup merge of #102044 - ChrisDenton:BCrypt-system-rand, r=thomcc
[rust.git] / src / tools / miri / tests / fail / stacked_borrows / illegal_read5.rs
1 // We *can* have aliasing &RefCell<T> and &mut T, but we cannot read through the former.
2 // Else we couldn't optimize based on the assumption that `xref` below is truly unique.
3 //@normalize-stderr-test: "0x[0-9a-fA-F]+" -> "$$HEX"
4
5 use std::cell::RefCell;
6 use std::{mem, ptr};
7
8 #[rustfmt::skip] // rustfmt bug: https://github.com/rust-lang/rustfmt/issues/5391
9 fn main() {
10     let rc = RefCell::new(0);
11     let mut refmut = rc.borrow_mut();
12     let xref: &mut i32 = &mut *refmut;
13     let xshr = &rc; // creating this is ok
14     let _val = *xref; // we can even still use our mutable reference
15     mem::forget(unsafe { ptr::read(xshr) }); // but after reading through the shared ref
16     let _val = *xref; // the mutable one is dead and gone
17     //~^ ERROR: /read access .* tag does not exist in the borrow stack/
18 }