about summary refs log tree commit diff
path: root/tests/ui/pattern
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/pattern')
-rw-r--r--tests/ui/pattern/array-length-mismatch-13482.rs7
-rw-r--r--tests/ui/pattern/array-length-mismatch-verbose-13482-2.rs9
-rw-r--r--tests/ui/pattern/struct-mismatch-destructure-14541.rs11
-rw-r--r--tests/ui/pattern/struct-wildcard-pattern-14308.rs15
4 files changed, 42 insertions, 0 deletions
diff --git a/tests/ui/pattern/array-length-mismatch-13482.rs b/tests/ui/pattern/array-length-mismatch-13482.rs
new file mode 100644
index 00000000000..244b3237e02
--- /dev/null
+++ b/tests/ui/pattern/array-length-mismatch-13482.rs
@@ -0,0 +1,7 @@
+fn main() {
+  let x = [1,2];
+  let y = match x {
+    [] => None, //~ ERROR pattern requires 0 elements but array has 2
+    [a,_] => Some(a)
+  };
+}
diff --git a/tests/ui/pattern/array-length-mismatch-verbose-13482-2.rs b/tests/ui/pattern/array-length-mismatch-verbose-13482-2.rs
new file mode 100644
index 00000000000..619e9d748ef
--- /dev/null
+++ b/tests/ui/pattern/array-length-mismatch-verbose-13482-2.rs
@@ -0,0 +1,9 @@
+//@ compile-flags:-Z verbose-internals
+
+fn main() {
+    let x = [1,2];
+    let y = match x {
+        [] => None, //~ ERROR pattern requires 0 elements but array has 2
+        [a,_] => Some(a)
+    };
+}
diff --git a/tests/ui/pattern/struct-mismatch-destructure-14541.rs b/tests/ui/pattern/struct-mismatch-destructure-14541.rs
new file mode 100644
index 00000000000..358d29419f9
--- /dev/null
+++ b/tests/ui/pattern/struct-mismatch-destructure-14541.rs
@@ -0,0 +1,11 @@
+struct Vec2 { y: f32 }
+struct Vec3 { y: f32, z: f32 }
+
+fn make(v: Vec2) {
+    let Vec3 { y: _, z: _ } = v;
+    //~^ ERROR mismatched types
+    //~| NOTE expected `Vec2`, found `Vec3`
+    //~| NOTE this expression has type `Vec2`
+}
+
+fn main() { }
diff --git a/tests/ui/pattern/struct-wildcard-pattern-14308.rs b/tests/ui/pattern/struct-wildcard-pattern-14308.rs
new file mode 100644
index 00000000000..724be160d06
--- /dev/null
+++ b/tests/ui/pattern/struct-wildcard-pattern-14308.rs
@@ -0,0 +1,15 @@
+//@ run-pass
+
+struct A(isize);
+
+fn main() {
+    let x = match A(3) {
+        A(..) => 1
+    };
+    assert_eq!(x, 1);
+    let x = match A(4) {
+        A(1) => 1,
+        A(..) => 2
+    };
+    assert_eq!(x, 2);
+}