]> git.lizzy.rs Git - rust.git/blob - src/tools/miri/tests/fail/stacked_borrows/return_invalid_mut_tuple.rs
Rollup merge of #105405 - sunfishcode:sunfishcode/export-dynamic, r=TaKO8Ki
[rust.git] / src / tools / miri / tests / fail / stacked_borrows / return_invalid_mut_tuple.rs
1 // Make sure that we cannot return a `&mut` that got already invalidated, not even in a tuple.
2 fn foo(x: &mut (i32, i32)) -> (&mut i32,) {
3     let xraw = x as *mut (i32, i32);
4     let ret = (unsafe { &mut (*xraw).1 },);
5     let _val = unsafe { *xraw }; // invalidate xref
6     ret //~ ERROR: /retag .* tag does not exist in the borrow stack/
7 }
8
9 fn main() {
10     foo(&mut (1, 2)).0;
11 }