]> git.lizzy.rs Git - rust.git/blob - src/test/ui/nll/issue-27282-reborrow-ref-mut-in-guard.rs
Auto merge of #103600 - compiler-errors:early-binder-nits, r=spastorino
[rust.git] / src / test / ui / nll / issue-27282-reborrow-ref-mut-in-guard.rs
1 // Issue 27282: This is a variation on issue-27282-move-ref-mut-into-guard.rs
2 //
3 // It reborrows instead of moving the `ref mut` pattern borrow. This
4 // means that our conservative check for mutation in guards will
5 // reject it. But I want to make sure that we continue to reject it
6 // (under NLL) even when that conservaive check goes away.
7
8 fn main() {
9     let mut b = &mut true;
10     match b {
11         &mut false => {},
12         ref mut r if { (|| { let bar = &mut *r; **bar = false; })();
13         //~^ ERROR cannot borrow `r` as mutable, as it is immutable for the pattern guard
14                              false } => { &mut *r; },
15         &mut true => { println!("You might think we should get here"); },
16         _ => panic!("surely we could never get here, since rustc warns it is unreachable."),
17     }
18 }