new compile-fail test involving non-reborrowing-cast-to-raw

This commit is contained in:
Ralf Jung 2020-01-30 12:21:37 +01:00
parent acd156d722
commit e0adfe4d45
2 changed files with 13 additions and 1 deletions

View file

@ -0,0 +1,13 @@
// Make sure that creating a raw ptr next to a shared ref works
// but the shared ref still gets invalidated when the raw ptr is used for writing.
fn main() { unsafe {
use std::mem;
let x = &mut 0;
let y1: &i32 = mem::transmute(&*x); // launder lifetimes
let y2 = x as *mut _;
let _val = *y2;
let _val = *y1;
*y2 += 1;
let _fail = *y1; //~ ERROR borrow stack
} }

View file

@ -136,7 +136,6 @@ fn shr_and_raw() { unsafe {
let y2 = x as *mut _;
let _val = *y1;
*y2 += 1;
// TODO: Once this works, add compile-fail test that tries to read from y1 again.
} }
fn disjoint_mutable_subborrows() {