1 // Make sure that we cannot return a `&` that got already invalidated, not even in an `Option`.
2 // Due to shallow reborrowing, the error only surfaces when we look into the `Option`.
foo(x: &mut (i32, i32)) -> Option<&i32>3 fn foo(x: &mut (i32, i32)) -> Option<&i32> {
4 let xraw = x as *mut (i32, i32);
5 let ret = Some(unsafe { &(*xraw).1 });
6 unsafe { *xraw = (42, 23) }; // unfreeze
7 ret
8 }
9
main()10 fn main() {
11 match foo(&mut (1, 2)) {
12 Some(_x) => {}, //~ ERROR borrow stack
13 None => {},
14 }
15 }
16