mirror of
https://github.com/rust-lang/rust.git
synced 2026-06-01 22:18:23 +03:00
test against passing invalid shared refs around
This commit is contained in:
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
Reference in New Issue
Block a user