]> git.lizzy.rs Git - rust.git/commitdiff
Add tests for #27282, #31287 as hard errors.
authorMazdak Farrokhzad <twingoow@gmail.com>
Sun, 28 Jul 2019 01:32:10 +0000 (03:32 +0200)
committerMazdak Farrokhzad <twingoow@gmail.com>
Tue, 30 Jul 2019 04:43:06 +0000 (06:43 +0200)
src/test/ui/borrowck/issue-27282-mutation-in-guard.rs [new file with mode: 0644]
src/test/ui/borrowck/issue-27282-mutation-in-guard.stderr [new file with mode: 0644]
src/test/ui/borrowck/issue-31287-drop-in-guard.rs [new file with mode: 0644]
src/test/ui/borrowck/issue-31287-drop-in-guard.stderr [new file with mode: 0644]

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 (file)
index 0000000..395c7d2
--- /dev/null
@@ -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 (file)
index 0000000..ea7df7d
--- /dev/null
@@ -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 (file)
index 0000000..07125b9
--- /dev/null
@@ -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 (file)
index 0000000..85c83ec
--- /dev/null
@@ -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`.