about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorDylan DPC <99973273+Dylan-DPC@users.noreply.github.com>2022-04-19 14:43:20 +0200
committerGitHub <noreply@github.com>2022-04-19 14:43:20 +0200
commit036d200d1c7634f2a65e0dd28b094aa1220bbce0 (patch)
tree8eaebb468b759b544c5a58bd60f8953800e33cac /src
parent35188440b5e3d02acdb02f616aad800c9c377dca (diff)
parentefe438b47441203c8e881e87f2f2e29db76d3ff7 (diff)
downloadrust-036d200d1c7634f2a65e0dd28b094aa1220bbce0.tar.gz
rust-036d200d1c7634f2a65e0dd28b094aa1220bbce0.zip
Rollup merge of #96122 - TaKO8Ki:fix-invalid-error-for-suggestion-to-add-slice-in-pattern-matching, r=nagisa
Fix an invalid error for a suggestion to add a slice in pattern-matching

closes #96103
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/suggestions/pattern-struct-with-slice-vec-field.rs35
-rw-r--r--src/test/ui/suggestions/pattern-struct-with-slice-vec-field.stderr15
2 files changed, 50 insertions, 0 deletions
diff --git a/src/test/ui/suggestions/pattern-struct-with-slice-vec-field.rs b/src/test/ui/suggestions/pattern-struct-with-slice-vec-field.rs
new file mode 100644
index 00000000000..5b223a91f50
--- /dev/null
+++ b/src/test/ui/suggestions/pattern-struct-with-slice-vec-field.rs
@@ -0,0 +1,35 @@
+use std::ops::Deref;
+
+struct Foo {
+    v: Vec<u32>,
+}
+
+struct Bar {
+    v: Vec<u32>,
+}
+
+impl Deref for Bar {
+    type Target = Vec<u32>;
+
+    fn deref(&self) -> &Self::Target {
+        &self.v
+    }
+}
+
+fn f(foo: &Foo) {
+    match foo {
+        Foo { v: [1, 2] } => {}
+        //~^ ERROR expected an array or slice, found `Vec<u32>
+        _ => {}
+    }
+}
+
+fn bar(bar: &Bar) {
+    match bar {
+        Bar { v: [1, 2] } => {}
+        //~^ ERROR expected an array or slice, found `Vec<u32>
+        _ => {}
+    }
+}
+
+fn main() {}
diff --git a/src/test/ui/suggestions/pattern-struct-with-slice-vec-field.stderr b/src/test/ui/suggestions/pattern-struct-with-slice-vec-field.stderr
new file mode 100644
index 00000000000..5b48a8b18a5
--- /dev/null
+++ b/src/test/ui/suggestions/pattern-struct-with-slice-vec-field.stderr
@@ -0,0 +1,15 @@
+error[E0529]: expected an array or slice, found `Vec<u32>`
+  --> $DIR/pattern-struct-with-slice-vec-field.rs:21:18
+   |
+LL |         Foo { v: [1, 2] } => {}
+   |                  ^^^^^^ pattern cannot match with input type `Vec<u32>`
+
+error[E0529]: expected an array or slice, found `Vec<u32>`
+  --> $DIR/pattern-struct-with-slice-vec-field.rs:29:18
+   |
+LL |         Bar { v: [1, 2] } => {}
+   |                  ^^^^^^ pattern cannot match with input type `Vec<u32>`
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0529`.