File tree Expand file tree Collapse file tree 3 files changed +30
-0
lines changed
tests/compile-fail/stacked_borrows Expand file tree Collapse file tree 3 files changed +30
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Make sure that we cannot load from memory a `&` that got already invalidated.
2
+ fn main ( ) {
3
+ let x = & mut 42 ;
4
+ let xraw = x as * mut _ ;
5
+ let xref = unsafe { & * xraw } ;
6
+ let xref_in_mem = Box :: new ( xref) ;
7
+ let _val = * x; // invalidate xraw
8
+ let _val = * xref_in_mem; //~ ERROR Shr reference with non-reactivatable tag: Location should be frozen
9
+ }
Original file line number Diff line number Diff line change
1
+ // Make sure that we cannot pass by argument a `&` that got already invalidated.
2
+ fn foo ( _: & i32 ) { }
3
+
4
+ fn main ( ) {
5
+ let x = & mut 42 ;
6
+ let xraw = & * x as * const _ ;
7
+ let xref = unsafe { & * xraw } ;
8
+ let _val = * x; // invalidate xraw
9
+ foo ( xref) ; //~ ERROR Shr reference with non-reactivatable tag: Location should be frozen
10
+ }
Original file line number Diff line number Diff line change
1
+ // Make sure that we cannot return a `&` that got already invalidated.
2
+ fn foo ( x : & mut ( i32 , i32 ) ) -> & i32 {
3
+ let xraw = x as * mut ( i32 , i32 ) ;
4
+ let ret = unsafe { & ( * xraw) . 1 } ;
5
+ let _val = * x; // invalidate xraw and its children
6
+ ret //~ ERROR Shr reference with non-reactivatable tag: Location should be frozen
7
+ }
8
+
9
+ fn main ( ) {
10
+ foo ( & mut ( 1 , 2 ) ) ;
11
+ }
You can’t perform that action at this time.
0 commit comments