rust/tests/compile-fail/stacked_borrows/illegal_write1.rs

13 lines
363 B
Rust
Raw Normal View History

2018-10-19 11:38:23 -05:00
fn evil(x: &u32) {
// 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() {
let target = Box::new(42); // has an implicit raw
let ref_ = &*target;
evil(ref_); // invalidates shared ref, activates raw
let _x = *ref_; //~ ERROR Shr reference with non-reactivatable tag
2018-10-19 11:38:23 -05:00
}