2018-10-19 11:38:23 -05:00
|
|
|
use std::mem;
|
|
|
|
|
|
|
|
fn main() {
|
2018-10-26 04:31:20 -05:00
|
|
|
let mut target = 42;
|
|
|
|
// Make sure we cannot use a raw-tagged `&mut` pointing to a frozen location.
|
|
|
|
// Even just creating it unfreezes.
|
|
|
|
let raw = &mut target as *mut _; // let this leak to raw
|
|
|
|
let reference = unsafe { &*raw }; // freeze
|
2022-06-26 20:14:18 -05:00
|
|
|
let _ptr = reference as *const _ as *mut i32; // raw ptr, with raw tag
|
|
|
|
let _mut_ref: &mut i32 = unsafe { mem::transmute(raw) }; // &mut, with raw tag
|
2018-10-26 04:31:20 -05:00
|
|
|
// Now we retag, making our ref top-of-stack -- and, in particular, unfreezing.
|
2019-04-16 10:17:28 -05:00
|
|
|
let _val = *reference; //~ ERROR borrow stack
|
2018-10-19 11:38:23 -05:00
|
|
|
}
|