test against passing invalid shared refs around
This commit is contained in:
parent
5388037f8a
commit
356369dd08
9
tests/compile-fail/stacked_borrows/load_invalid_shr.rs
Normal file
9
tests/compile-fail/stacked_borrows/load_invalid_shr.rs
Normal file
@ -0,0 +1,9 @@
|
||||
// Make sure that we cannot load from memory a `&` that got already invalidated.
|
||||
fn main() {
|
||||
let x = &mut 42;
|
||||
let xraw = x as *mut _;
|
||||
let xref = unsafe { &*xraw };
|
||||
let xref_in_mem = Box::new(xref);
|
||||
let _val = *x; // invalidate xraw
|
||||
let _val = *xref_in_mem; //~ ERROR Shr reference with non-reactivatable tag: Location should be frozen
|
||||
}
|
10
tests/compile-fail/stacked_borrows/pass_invalid_shr.rs
Normal file
10
tests/compile-fail/stacked_borrows/pass_invalid_shr.rs
Normal file
@ -0,0 +1,10 @@
|
||||
// Make sure that we cannot pass by argument a `&` that got already invalidated.
|
||||
fn foo(_: &i32) {}
|
||||
|
||||
fn main() {
|
||||
let x = &mut 42;
|
||||
let xraw = &*x as *const _;
|
||||
let xref = unsafe { &*xraw };
|
||||
let _val = *x; // invalidate xraw
|
||||
foo(xref); //~ ERROR Shr reference with non-reactivatable tag: Location should be frozen
|
||||
}
|
11
tests/compile-fail/stacked_borrows/return_invalid_shr.rs
Normal file
11
tests/compile-fail/stacked_borrows/return_invalid_shr.rs
Normal file
@ -0,0 +1,11 @@
|
||||
// Make sure that we cannot return a `&` that got already invalidated.
|
||||
fn foo(x: &mut (i32, i32)) -> &i32 {
|
||||
let xraw = x as *mut (i32, i32);
|
||||
let ret = unsafe { &(*xraw).1 };
|
||||
let _val = *x; // invalidate xraw and its children
|
||||
ret //~ ERROR Shr reference with non-reactivatable tag: Location should be frozen
|
||||
}
|
||||
|
||||
fn main() {
|
||||
foo(&mut (1, 2));
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user