]> git.lizzy.rs Git - rust.git/blob - src/test/ui/nll/match-guards-always-borrow.rs
Update tests for changes to cannot move errors
[rust.git] / src / test / ui / nll / match-guards-always-borrow.rs
1 #![feature(nll)]
2
3 // Here is arielb1's basic example from rust-lang/rust#27282
4 // that AST borrowck is flummoxed by:
5
6 fn should_reject_destructive_mutate_in_guard() {
7     match Some(&4) {
8         None => {},
9         ref mut foo if {
10             (|| { let bar = foo; bar.take() })();
11             //~^ ERROR cannot move out of `foo` in pattern guard [E0507]
12             false } => { },
13         Some(s) => std::process::exit(*s),
14     }
15 }
16
17 // Here below is a case that needs to keep working: we only use the
18 // binding via immutable-borrow in the guard, and we mutate in the arm
19 // body.
20 fn allow_mutate_in_arm_body() {
21     match Some(&4) {
22         None => {},
23         ref mut foo if foo.is_some() && false => { foo.take(); () }
24         Some(s) => std::process::exit(*s),
25     }
26 }
27
28 // Here below is a case that needs to keep working: we only use the
29 // binding via immutable-borrow in the guard, and we move into the arm
30 // body.
31 fn allow_move_into_arm_body() {
32     match Some(&4) {
33         None => {},
34         mut foo if foo.is_some() && false => { foo.take(); () }
35         Some(s) => std::process::exit(*s),
36     }
37 }
38
39 fn main() {
40     should_reject_destructive_mutate_in_guard();
41     allow_mutate_in_arm_body();
42     allow_move_into_arm_body();
43 }