mirror of
https://github.com/rust-lang/rust.git
synced 2026-06-02 06:28:20 +03:00
add some tests for retagging inside tuples and options
This commit is contained in:
@@ -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));
|
||||
}
|
||||
Reference in New Issue
Block a user