]> git.lizzy.rs Git - rust.git/commitdiff
Add tests
authorNadrieril <nadrieril+git@gmail.com>
Thu, 17 Dec 2020 00:42:49 +0000 (00:42 +0000)
committerNadrieril <nadrieril+git@gmail.com>
Fri, 18 Dec 2020 16:21:38 +0000 (16:21 +0000)
src/test/ui/or-patterns/exhaustiveness-unreachable-pattern.rs
src/test/ui/or-patterns/exhaustiveness-unreachable-pattern.stderr
src/test/ui/pattern/usefulness/issue-15129.rs
src/test/ui/pattern/usefulness/issue-2111.rs
src/test/ui/pattern/usefulness/issue-2111.stderr
src/test/ui/pattern/usefulness/issue-56379.rs [new file with mode: 0644]
src/test/ui/pattern/usefulness/issue-56379.stderr [new file with mode: 0644]

index 512f1e283cb462a0cff4ace899421714bd4c4d4d..178a4aa6681a0759e7c26e468a10c5f2c12a3710 100644 (file)
@@ -64,6 +64,37 @@ fn main() {
             | 2, ..] => {}
         _ => {}
     }
+    // FIXME: incorrect
+    match &[][..] {
+        [true] => {}
+        [true //~ ERROR unreachable
+            | false, ..] => {}
+        _ => {}
+    }
+    match &[][..] {
+        [false] => {}
+        [true, ..] => {}
+        [true //~ ERROR unreachable
+            | false, ..] => {}
+        _ => {}
+    }
+    match (true, None) {
+        (true, Some(_)) => {}
+        (false, Some(true)) => {}
+        (true | false, None | Some(true // FIXME: should be unreachable
+                                   | false)) => {}
+    }
+    macro_rules! t_or_f {
+        () => {
+            (true // FIXME: should be unreachable
+                        | false)
+        };
+    }
+    match (true, None) {
+        (true, Some(_)) => {}
+        (false, Some(true)) => {}
+        (true | false, None | Some(t_or_f!())) => {}
+    }
     match Some(0) {
         Some(0) => {}
         Some(0 //~ ERROR unreachable
index e968310d108dda3c8f817fbde18b53a310b40497..38e2369ae7dbaf78ba90d08840cc17fde3722280 100644 (file)
@@ -95,28 +95,40 @@ LL |         [1
    |          ^
 
 error: unreachable pattern
-  --> $DIR/exhaustiveness-unreachable-pattern.rs:69:14
+  --> $DIR/exhaustiveness-unreachable-pattern.rs:70:10
+   |
+LL |         [true
+   |          ^^^^
+
+error: unreachable pattern
+  --> $DIR/exhaustiveness-unreachable-pattern.rs:77:10
+   |
+LL |         [true
+   |          ^^^^
+
+error: unreachable pattern
+  --> $DIR/exhaustiveness-unreachable-pattern.rs:100:14
    |
 LL |         Some(0
    |              ^
 
 error: unreachable pattern
-  --> $DIR/exhaustiveness-unreachable-pattern.rs:88:19
+  --> $DIR/exhaustiveness-unreachable-pattern.rs:119:19
    |
 LL |                 | false) => {}
    |                   ^^^^^
 
 error: unreachable pattern
-  --> $DIR/exhaustiveness-unreachable-pattern.rs:96:15
+  --> $DIR/exhaustiveness-unreachable-pattern.rs:127:15
    |
 LL |             | true) => {}
    |               ^^^^
 
 error: unreachable pattern
-  --> $DIR/exhaustiveness-unreachable-pattern.rs:102:15
+  --> $DIR/exhaustiveness-unreachable-pattern.rs:133:15
    |
 LL |             | true,
    |               ^^^^
 
-error: aborting due to 19 previous errors
+error: aborting due to 21 previous errors
 
index ed134c175eddbe722df82d90934b41a78e858fb1..bcfc32be9a483e0dbdf7d17286c0ccf6d114a931 100644 (file)
@@ -1,17 +1,17 @@
 pub enum T {
     T1(()),
-    T2(())
+    T2(()),
 }
 
 pub enum V {
     V1(isize),
-    V2(bool)
+    V2(bool),
 }
 
 fn main() {
     match (T::T1(()), V::V2(true)) {
-    //~^ ERROR non-exhaustive patterns: `(T1(()), V2(_))` not covered
+        //~^ ERROR non-exhaustive patterns: `(T1(()), V2(_))` not covered
         (T::T1(()), V::V1(i)) => (),
-        (T::T2(()), V::V2(b)) => ()
+        (T::T2(()), V::V2(b)) => (),
     }
 }
index 7e5835e8697a331553fbd0948e45d434c91b0599..0847045cdaa912c5f5bc178f5a8ca81c832c6aaf 100644 (file)
@@ -1,12 +1,11 @@
 fn foo(a: Option<usize>, b: Option<usize>) {
-  match (a,b) {
-  //~^ ERROR: non-exhaustive patterns: `(None, None)` not covered
-    (Some(a), Some(b)) if a == b => { }
-    (Some(_), None) |
-    (None, Some(_)) => { }
-  }
+    match (a, b) {
+        //~^ ERROR: non-exhaustive patterns: `(None, None)` not covered
+        (Some(a), Some(b)) if a == b => {}
+        (Some(_), None) | (None, Some(_)) => {}
+    }
 }
 
 fn main() {
-  foo(None, None);
+    foo(None, None);
 }
index a39a479e078d928d5f95131ebded1aba3961227a..f0609ccebc162707934c1fadc4d6f122a0ae2b5a 100644 (file)
@@ -1,8 +1,8 @@
 error[E0004]: non-exhaustive patterns: `(None, None)` not covered
-  --> $DIR/issue-2111.rs:2:9
+  --> $DIR/issue-2111.rs:2:11
    |
-LL |   match (a,b) {
-   |         ^^^^^ pattern `(None, None)` not covered
+LL |     match (a, b) {
+   |           ^^^^^^ pattern `(None, None)` not covered
    |
    = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
    = note: the matched value is of type `(Option<usize>, Option<usize>)`
diff --git a/src/test/ui/pattern/usefulness/issue-56379.rs b/src/test/ui/pattern/usefulness/issue-56379.rs
new file mode 100644 (file)
index 0000000..5454e80
--- /dev/null
@@ -0,0 +1,14 @@
+enum Foo {
+    A(bool),
+    B(bool),
+    C(bool),
+}
+
+fn main() {
+    match Foo::A(true) {
+        //~^ ERROR non-exhaustive patterns: `A(false)` not covered
+        Foo::A(true) => {}
+        Foo::B(true) => {}
+        Foo::C(true) => {}
+    }
+}
diff --git a/src/test/ui/pattern/usefulness/issue-56379.stderr b/src/test/ui/pattern/usefulness/issue-56379.stderr
new file mode 100644 (file)
index 0000000..661e0db
--- /dev/null
@@ -0,0 +1,20 @@
+error[E0004]: non-exhaustive patterns: `A(false)` not covered
+  --> $DIR/issue-56379.rs:8:11
+   |
+LL | / enum Foo {
+LL | |     A(bool),
+   | |     - not covered
+LL | |     B(bool),
+LL | |     C(bool),
+LL | | }
+   | |_- `Foo` defined here
+...
+LL |       match Foo::A(true) {
+   |             ^^^^^^^^^^^^ pattern `A(false)` not covered
+   |
+   = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
+   = note: the matched value is of type `Foo`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0004`.