File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed
compile-fail/stacked_borrows Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change
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
+ } }
Original file line number Diff line number Diff line change @@ -136,7 +136,6 @@ fn shr_and_raw() { unsafe {
136
136
let y2 = x as * mut _ ;
137
137
let _val = * y1;
138
138
* y2 += 1 ;
139
- // TODO: Once this works, add compile-fail test that tries to read from y1 again.
140
139
} }
141
140
142
141
fn disjoint_mutable_subborrows ( ) {
You can’t perform that action at this time.
0 commit comments