]> git.lizzy.rs Git - rust.git/blob - src/tools/miri/tests/fail/stacked_borrows/shared_rw_borrows_are_weak2.rs
Rollup merge of #102044 - ChrisDenton:BCrypt-system-rand, r=thomcc
[rust.git] / src / tools / miri / tests / fail / stacked_borrows / shared_rw_borrows_are_weak2.rs
1 // We want to test that granting a SharedReadWrite will be added
2 // *below* an already granted SharedReadWrite -- so writing to
3 // the SharedReadWrite will invalidate the SharedReadWrite.
4 //@normalize-stderr-test: "0x[0-9a-fA-F]+" -> "$$HEX"
5
6 use std::cell::RefCell;
7 use std::mem;
8
9 fn main() {
10     unsafe {
11         let x = &mut RefCell::new(0);
12         let y: &i32 = mem::transmute(&*x.borrow()); // launder lifetime
13         let shr_rw = &*x; // thanks to interior mutability this will be a SharedReadWrite
14         shr_rw.replace(1);
15         let _val = *y; //~ ERROR: /read access .* tag does not exist in the borrow stack/
16     }
17 }