]> git.lizzy.rs Git - rust.git/blob - tests/ui/nll/issue-27282-move-match-input-into-guard.rs
Auto merge of #101138 - Rejyr:diagnostic-migration-rustc-lint-pt2, r=davidtwco
[rust.git] / tests / 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 #![feature(if_let_guard)]
11
12 fn main() {
13     let b = &mut true;
14     match b {
15         //~^ ERROR use of moved value: `b` [E0382]
16         &mut false => {},
17         _ if { (|| { let bar = b; *bar = false; })();
18                      false } => { },
19         &mut true => { println!("You might think we should get here"); },
20         _ => panic!("surely we could never get here, since rustc warns it is unreachable."),
21     }
22
23     let b = &mut true;
24     match b {
25         //~^ ERROR use of moved value: `b` [E0382]
26         &mut false => {}
27         _ if let Some(()) = {
28             (|| { let bar = b; *bar = false; })();
29             None
30         } => {}
31         &mut true => {}
32         _ => {}
33     }
34 }