about summary refs log tree commit diff
path: root/src/test/ui/issues
diff options
context:
space:
mode:
authorLéo Lanteri Thauvin <leseulartichaut@gmail.com>2022-12-21 16:29:35 +0100
committerLéo Lanteri Thauvin <leseulartichaut@gmail.com>2022-12-21 19:24:33 +0100
commit56aaf749b63824428348268dde37b84634647c4f (patch)
tree6a192a20ed7cbaa4d4094dd6eb0f959bf21cc1e0 /src/test/ui/issues
parent1d12c3cea30b8ba4a09650a9e9c46fe9fbe25f0b (diff)
Test the borrowck behavior of if-let guards
Diffstat (limited to 'src/test/ui/issues')
-rw-r--r--src/test/ui/issues/issue-29723.rs8
-rw-r--r--src/test/ui/issues/issue-29723.stderr20
2 files changed, 26 insertions, 2 deletions
diff --git a/src/test/ui/issues/issue-29723.rs b/src/test/ui/issues/issue-29723.rs
index ce91022f093..399e9ba0df7 100644
--- a/src/test/ui/issues/issue-29723.rs
+++ b/src/test/ui/issues/issue-29723.rs
@@ -1,5 +1,7 @@
 // test for https://github.com/rust-lang/rust/issues/29723
 
+#![feature(if_let_guard)]
+
 fn main() {
     let s = String::new();
     let _s = match 0 {
@@ -11,4 +13,10 @@ fn main() {
             //~^ ERROR use of moved value: `s`
         }
     };
+
+    let s = String::new();
+    let _s = match 0 {
+        0 if let Some(()) = { drop(s); None } => String::from("oops"),
+        _ => s //~ ERROR use of moved value: `s`
+    };
 }
diff --git a/src/test/ui/issues/issue-29723.stderr b/src/test/ui/issues/issue-29723.stderr
index 92ee5cf22b7..044d8a9b5dd 100644
--- a/src/test/ui/issues/issue-29723.stderr
+++ b/src/test/ui/issues/issue-29723.stderr
@@ -1,5 +1,5 @@
 error[E0382]: use of moved value: `s`
-  --> $DIR/issue-29723.rs:10:13
+  --> $DIR/issue-29723.rs:12:13
    |
 LL |     let s = String::new();
    |         - move occurs because `s` has type `String`, which does not implement the `Copy` trait
@@ -15,6 +15,22 @@ help: consider cloning the value if the performance cost is acceptable
 LL |         0 if { drop(s.clone()); false } => String::from("oops"),
    |                      ++++++++
 
-error: aborting due to previous error
+error[E0382]: use of moved value: `s`
+  --> $DIR/issue-29723.rs:20:14
+   |
+LL |     let s = String::new();
+   |         - move occurs because `s` has type `String`, which does not implement the `Copy` trait
+LL |     let _s = match 0 {
+LL |         0 if let Some(()) = { drop(s); None } => String::from("oops"),
+   |                                    - value moved here
+LL |         _ => s
+   |              ^ value used here after move
+   |
+help: consider cloning the value if the performance cost is acceptable
+   |
+LL |         0 if let Some(()) = { drop(s.clone()); None } => String::from("oops"),
+   |                                     ++++++++
+
+error: aborting due to 2 previous errors
 
 For more information about this error, try `rustc --explain E0382`.