]> git.lizzy.rs Git - rust.git/blob - src/test/ui/nll/issue-27282-move-match-input-into-guard.rs
Auto merge of #105121 - oli-obk:simpler-cheaper-dump_mir, r=nnethercote
[rust.git] / src / test / ui / nll / issue-27282-move-match-input-into-guard.rs
1 // Issue 27282: Example 2: This sidesteps the AST checks disallowing
2 // mutable borrows in match guards by hiding the mutable borrow in a
3 // guard behind a move (of the mutably borrowed match input) within a
4 // closure.
5 //
6 // This example is not rejected by AST borrowck (and then reliably
7 // reaches the panic code when executed, despite the compiler warning
8 // about that match arm being unreachable.
9
10 fn main() {
11     let b = &mut true;
12     match b {
13         //~^ ERROR use of moved value: `b` [E0382]
14         &mut false => {},
15         _ if { (|| { let bar = b; *bar = false; })();
16                      false } => { },
17         &mut true => { println!("You might think we should get here"); },
18         _ => panic!("surely we could never get here, since rustc warns it is unreachable."),
19     }
20 }