about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2022-02-17 06:30:00 +0100
committerGitHub <noreply@github.com>2022-02-17 06:30:00 +0100
commit2c0df80a2ebf01c7200b17496b29ce3520420068 (patch)
treeff7d665f8727536e2a5fe43cad0f4b57aa4d4ca3 /src/test
parent351aa1b5dabe51ae4fcdfc23db51ce60f6699cf0 (diff)
parentd9592d90c707ff1badb8067eb0a0e252d241ee9e (diff)
downloadrust-2c0df80a2ebf01c7200b17496b29ce3520420068.tar.gz
rust-2c0df80a2ebf01c7200b17496b29ce3520420068.zip
Rollup merge of #93981 - ChayimFriedman2:slice-pat-reference-option-result, r=davidtwco
Fix suggestion to slice if scurtinee is a reference to `Result` or `Option`

Fixes https://github.com/rust-lang/rust/pull/91343#issuecomment-1037718339 and https://github.com/rust-lang/rust/pull/91343#discussion_r761466979.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/typeck/issue-91328.fixed10
-rw-r--r--src/test/ui/typeck/issue-91328.rs10
-rw-r--r--src/test/ui/typeck/issue-91328.stderr11
3 files changed, 30 insertions, 1 deletions
diff --git a/src/test/ui/typeck/issue-91328.fixed b/src/test/ui/typeck/issue-91328.fixed
index 81b6a996072..c0384399a92 100644
--- a/src/test/ui/typeck/issue-91328.fixed
+++ b/src/test/ui/typeck/issue-91328.fixed
@@ -34,4 +34,14 @@ fn baz(v: Vec<i32>) -> i32 {
     }
 }
 
+fn qux(a: &Option<Box<[i32; 2]>>) -> i32 {
+    match a.as_deref() {
+    //~^ HELP: consider using `as_deref` here
+        Some([a, b]) => a + b,
+        //~^ ERROR: expected an array or slice
+        //~| NOTE: pattern cannot match with input type
+        _ => 42,
+    }
+}
+
 fn main() {}
diff --git a/src/test/ui/typeck/issue-91328.rs b/src/test/ui/typeck/issue-91328.rs
index e938d8f5c9f..63602d26f97 100644
--- a/src/test/ui/typeck/issue-91328.rs
+++ b/src/test/ui/typeck/issue-91328.rs
@@ -34,4 +34,14 @@ fn baz(v: Vec<i32>) -> i32 {
     }
 }
 
+fn qux(a: &Option<Box<[i32; 2]>>) -> i32 {
+    match a {
+    //~^ HELP: consider using `as_deref` here
+        Some([a, b]) => a + b,
+        //~^ ERROR: expected an array or slice
+        //~| NOTE: pattern cannot match with input type
+        _ => 42,
+    }
+}
+
 fn main() {}
diff --git a/src/test/ui/typeck/issue-91328.stderr b/src/test/ui/typeck/issue-91328.stderr
index 96ad00cde4f..f2f407bcaff 100644
--- a/src/test/ui/typeck/issue-91328.stderr
+++ b/src/test/ui/typeck/issue-91328.stderr
@@ -25,6 +25,15 @@ LL |
 LL |         [a, b] => a + b,
    |         ^^^^^^ pattern cannot match with input type `Vec<i32>`
 
-error: aborting due to 3 previous errors
+error[E0529]: expected an array or slice, found `Box<[i32; 2]>`
+  --> $DIR/issue-91328.rs:40:14
+   |
+LL |     match a {
+   |           - help: consider using `as_deref` here: `a.as_deref()`
+LL |
+LL |         Some([a, b]) => a + b,
+   |              ^^^^^^ pattern cannot match with input type `Box<[i32; 2]>`
+
+error: aborting due to 4 previous errors
 
 For more information about this error, try `rustc --explain E0529`.