]> git.lizzy.rs Git - rust.git/blob - src/test/ui/issues/issue-27282-move-match-input-into-guard.rs
Rollup merge of #62337 - Mark-Simulacrum:fix-cpu-usage-script, r=alexcrichton
[rust.git] / src / test / ui / issues / 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 #![feature(nll)]
11
12 fn main() {
13     let b = &mut true;
14     match b {
15         &mut false => {},
16         _ if { (|| { let bar = b; *bar = false; })();
17                      false } => { },
18         &mut true => { println!("You might think we should get here"); },
19         //~^ ERROR use of moved value: `b` [E0382]
20         _ => panic!("surely we could never get here, since rustc warns it is unreachable."),
21     }
22 }