2018-10-19 11:38:23 -05:00
|
|
|
fn evil(x: &u32) {
|
2018-10-22 11:01:32 -05:00
|
|
|
// mutating shared ref without `UnsafeCell`
|
|
|
|
let x : *mut u32 = x as *const _ as *mut _;
|
|
|
|
unsafe { *x = 42; }
|
2018-10-19 11:38:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2018-10-22 11:01:32 -05:00
|
|
|
let target = Box::new(42); // has an implicit raw
|
|
|
|
let ref_ = &*target;
|
|
|
|
evil(ref_); // invalidates shared ref, activates raw
|
2018-11-05 09:05:17 -06:00
|
|
|
let _x = *ref_; //~ ERROR is not frozen long enough
|
2018-10-19 11:38:23 -05:00
|
|
|
}
|