Skip to content

Commit e0adfe4

Browse files
committed
new compile-fail test involving non-reborrowing-cast-to-raw
1 parent acd156d commit e0adfe4

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Make sure that creating a raw ptr next to a shared ref works
2+
// but the shared ref still gets invalidated when the raw ptr is used for writing.
3+
4+
fn main() { unsafe {
5+
use std::mem;
6+
let x = &mut 0;
7+
let y1: &i32 = mem::transmute(&*x); // launder lifetimes
8+
let y2 = x as *mut _;
9+
let _val = *y2;
10+
let _val = *y1;
11+
*y2 += 1;
12+
let _fail = *y1; //~ ERROR borrow stack
13+
} }

tests/run-pass/stacked-borrows/stacked-borrows.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ fn shr_and_raw() { unsafe {
136136
let y2 = x as *mut _;
137137
let _val = *y1;
138138
*y2 += 1;
139-
// TODO: Once this works, add compile-fail test that tries to read from y1 again.
140139
} }
141140

142141
fn disjoint_mutable_subborrows() {

0 commit comments

Comments
 (0)