--- /dev/null
+fn main() {
+ match Some(&4) {
+ None => {},
+ ref mut foo
+ if {
+ (|| { let bar = foo; bar.take() })();
+ //~^ ERROR cannot move out of `foo` in pattern guard
+ false
+ } => {},
+ Some(ref _s) => println!("Note this arm is bogus; the `Some` became `None` in the guard."),
+ _ => println!("Here is some supposedly unreachable code."),
+ }
+}
--- /dev/null
+error[E0507]: cannot move out of `foo` in pattern guard
+ --> $DIR/issue-27282-mutation-in-guard.rs:6:18
+ |
+LL | (|| { let bar = foo; bar.take() })();
+ | ^^ ---
+ | | |
+ | | move occurs because `foo` has type `&mut std::option::Option<&i32>`, which does not implement the `Copy` trait
+ | | move occurs due to use in closure
+ | move out of `foo` occurs here
+ |
+ = note: variables bound in patterns cannot be moved from until after the end of the pattern guard
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0507`.
--- /dev/null
+fn main() {
+ let a = Some("...".to_owned());
+ let b = match a {
+ Some(_) if { drop(a); false } => None,
+ x => x, //~ ERROR use of moved value: `a`
+ };
+ println!("{:?}", b);
+}
--- /dev/null
+error[E0382]: use of moved value: `a`
+ --> $DIR/issue-31287-drop-in-guard.rs:5:9
+ |
+LL | let a = Some("...".to_owned());
+ | - move occurs because `a` has type `std::option::Option<std::string::String>`, which does not implement the `Copy` trait
+LL | let b = match a {
+LL | Some(_) if { drop(a); false } => None,
+ | - value moved here
+LL | x => x,
+ | ^ value used here after move
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0382`.