]> git.lizzy.rs Git - rust.git/blob - tests/compile-fail/stacked_borrows/return_invalid_shr_tuple.rs
060fa25c2307e9f6e468a99fd20714f83a943ec2
[rust.git] / tests / compile-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 fn foo(x: &mut (i32, i32)) -> (&i32,) {
3     let xraw = x as *mut (i32, i32);
4     let ret = (unsafe { &(*xraw).1 },);
5     unsafe { *xraw = (42, 23) }; // unfreeze
6     ret //~ ERROR is not frozen
7 }
8
9 fn main() {
10     foo(&mut (1, 2));
11 }