]> git.lizzy.rs Git - rust.git/blob - src/tools/miri/tests/fail/stacked_borrows/return_invalid_shr_tuple.rs
Rollup merge of #102107 - Urgau:rustdoc-missing-space-before-where-clause, r=Guillaum...
[rust.git] / src / tools / miri / tests / fail / stacked_borrows / return_invalid_shr_tuple.rs
1 // Make sure that we cannot return a `&` that got already invalidated, not even in a tuple.
2 // Due to shallow reborrowing, the error only surfaces when we look into the tuple.
3 fn foo(x: &mut (i32, i32)) -> (&i32,) {
4     let xraw = x as *mut (i32, i32);
5     let ret = (unsafe { &(*xraw).1 },);
6     unsafe { *xraw = (42, 23) }; // unfreeze
7     ret
8 }
9
10 fn main() {
11     foo(&mut (1, 2)).0; //~ ERROR: /retag .* tag does not exist in the borrow stack/
12 }