1 // Here is arielb1's basic example from rust-lang/rust#27282
2 // that AST borrowck is flummoxed by:
4 fn should_reject_destructive_mutate_in_guard() {
8 (|| { let bar = foo; bar.take() })();
9 //~^ ERROR cannot move out of `foo` in pattern guard [E0507]
11 Some(s) => std::process::exit(*s),
15 // Here below is a case that needs to keep working: we only use the
16 // binding via immutable-borrow in the guard, and we mutate in the arm
18 fn allow_mutate_in_arm_body() {
21 ref mut foo if foo.is_some() && false => { foo.take(); () }
22 Some(s) => std::process::exit(*s),
26 // Here below is a case that needs to keep working: we only use the
27 // binding via immutable-borrow in the guard, and we move into the arm
29 fn allow_move_into_arm_body() {
32 mut foo if foo.is_some() && false => { foo.take(); () }
33 Some(s) => std::process::exit(*s),
38 should_reject_destructive_mutate_in_guard();
39 allow_mutate_in_arm_body();
40 allow_move_into_arm_body();