add some tests for retagging inside tuples and options
This commit is contained in:
parent
a1f895d6f2
commit
c54dcf59ae
4 changed files with 44 additions and 0 deletions
|
|
@ -0,0 +1,11 @@
|
|||
// Make sure that we cannot return a `&mut` that got already invalidated, not even in an `Option`.
|
||||
fn foo(x: &mut (i32, i32)) -> Option<&mut i32> {
|
||||
let xraw = x as *mut (i32, i32);
|
||||
let ret = Some(unsafe { &mut (*xraw).1 });
|
||||
let _val = unsafe { *xraw }; // invalidate xref
|
||||
ret //~ ERROR does not exist on the stack
|
||||
}
|
||||
|
||||
fn main() {
|
||||
foo(&mut (1, 2));
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
// Make sure that we cannot return a `&mut` that got already invalidated, not even in a tuple.
|
||||
fn foo(x: &mut (i32, i32)) -> (&mut i32,) {
|
||||
let xraw = x as *mut (i32, i32);
|
||||
let ret = (unsafe { &mut (*xraw).1 },);
|
||||
let _val = unsafe { *xraw }; // invalidate xref
|
||||
ret //~ ERROR does not exist on the stack
|
||||
}
|
||||
|
||||
fn main() {
|
||||
foo(&mut (1, 2));
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
// Make sure that we cannot return a `&` that got already invalidated, not even in an `Option`.
|
||||
fn foo(x: &mut (i32, i32)) -> Option<&i32> {
|
||||
let xraw = x as *mut (i32, i32);
|
||||
let ret = Some(unsafe { &(*xraw).1 });
|
||||
unsafe { *xraw = (42, 23) }; // unfreeze
|
||||
ret //~ ERROR is not frozen
|
||||
}
|
||||
|
||||
fn main() {
|
||||
foo(&mut (1, 2));
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
// Make sure that we cannot return a `&` that got already invalidated, not even in a tuple.
|
||||
fn foo(x: &mut (i32, i32)) -> (&i32,) {
|
||||
let xraw = x as *mut (i32, i32);
|
||||
let ret = (unsafe { &(*xraw).1 },);
|
||||
unsafe { *xraw = (42, 23) }; // unfreeze
|
||||
ret //~ ERROR is not frozen
|
||||
}
|
||||
|
||||
fn main() {
|
||||
foo(&mut (1, 2));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue