]> git.lizzy.rs Git - rust.git/blob - src/tools/miri/tests/fail/stacked_borrows/illegal_write4.rs
Rollup merge of #105502 - chenyukang:yukang/fix-105366-impl, r=estebank
[rust.git] / src / tools / miri / tests / fail / stacked_borrows / illegal_write4.rs
1 use std::mem;
2
3 fn main() {
4     let mut target = 42;
5     // Make sure we cannot use a raw-tagged `&mut` pointing to a frozen location.
6     // Even just creating it unfreezes.
7     let raw = &mut target as *mut _; // let this leak to raw
8     let reference = unsafe { &*raw }; // freeze
9     let _ptr = reference as *const _ as *mut i32; // raw ptr, with raw tag
10     let _mut_ref: &mut i32 = unsafe { mem::transmute(raw) }; // &mut, with raw tag
11     // Now we retag, making our ref top-of-stack -- and, in particular, unfreezing.
12     let _val = *reference; //~ ERROR: /read access .* tag does not exist in the borrow stack/
13 }