about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/borrowck/issue-27282-mutation-in-guard.rs13
-rw-r--r--src/test/ui/borrowck/issue-27282-mutation-in-guard.stderr15
-rw-r--r--src/test/ui/borrowck/issue-31287-drop-in-guard.rs8
-rw-r--r--src/test/ui/borrowck/issue-31287-drop-in-guard.stderr14
4 files changed, 50 insertions, 0 deletions
diff --git a/src/test/ui/borrowck/issue-27282-mutation-in-guard.rs b/src/test/ui/borrowck/issue-27282-mutation-in-guard.rs
new file mode 100644
index 00000000000..395c7d214d0
--- /dev/null
+++ b/src/test/ui/borrowck/issue-27282-mutation-in-guard.rs
@@ -0,0 +1,13 @@
+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."),
+    }
+}
diff --git a/src/test/ui/borrowck/issue-27282-mutation-in-guard.stderr b/src/test/ui/borrowck/issue-27282-mutation-in-guard.stderr
new file mode 100644
index 00000000000..ea7df7d5a7b
--- /dev/null
+++ b/src/test/ui/borrowck/issue-27282-mutation-in-guard.stderr
@@ -0,0 +1,15 @@
+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`.
diff --git a/src/test/ui/borrowck/issue-31287-drop-in-guard.rs b/src/test/ui/borrowck/issue-31287-drop-in-guard.rs
new file mode 100644
index 00000000000..07125b98a1f
--- /dev/null
+++ b/src/test/ui/borrowck/issue-31287-drop-in-guard.rs
@@ -0,0 +1,8 @@
+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);
+}
diff --git a/src/test/ui/borrowck/issue-31287-drop-in-guard.stderr b/src/test/ui/borrowck/issue-31287-drop-in-guard.stderr
new file mode 100644
index 00000000000..85c83ec4d70
--- /dev/null
+++ b/src/test/ui/borrowck/issue-31287-drop-in-guard.stderr
@@ -0,0 +1,14 @@
+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`.