about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNadrieril <nadrieril+git@gmail.com>2020-11-12 17:24:42 +0000
committerNadrieril <nadrieril+git@gmail.com>2020-11-12 17:24:42 +0000
commit257ed899c86acf6b4ee0f6dc9d6cfc9eb98e35a5 (patch)
tree28995747f5df4ee0c851a2548937e220ddf5f306
parenta601302ff0217b91589b5a7310a8a23adb843fdc (diff)
downloadrust-257ed899c86acf6b4ee0f6dc9d6cfc9eb98e35a5.tar.gz
rust-257ed899c86acf6b4ee0f6dc9d6cfc9eb98e35a5.zip
Add tests
-rw-r--r--src/test/ui/pattern/usefulness/match-empty-exhaustive_patterns.rs13
-rw-r--r--src/test/ui/pattern/usefulness/match-empty-exhaustive_patterns.stderr52
-rw-r--r--src/test/ui/pattern/usefulness/match-empty.rs20
-rw-r--r--src/test/ui/pattern/usefulness/match-empty.stderr45
4 files changed, 88 insertions, 42 deletions
diff --git a/src/test/ui/pattern/usefulness/match-empty-exhaustive_patterns.rs b/src/test/ui/pattern/usefulness/match-empty-exhaustive_patterns.rs
index 57b6b910ca1..c8d6e95dd6e 100644
--- a/src/test/ui/pattern/usefulness/match-empty-exhaustive_patterns.rs
+++ b/src/test/ui/pattern/usefulness/match-empty-exhaustive_patterns.rs
@@ -1,4 +1,5 @@
 #![feature(never_type)]
+#![feature(never_type_fallback)]
 #![feature(exhaustive_patterns)]
 #![deny(unreachable_patterns)]
 enum Foo {}
@@ -42,7 +43,17 @@ macro_rules! match_false {
 }
 
 fn foo(x: Foo) {
-    match_empty!(x); // ok
+    match x {} // ok
+    match x {
+        _ => {}, //~ ERROR unreachable pattern
+    }
+    match x {
+        _ if false => {}, //~ ERROR unreachable pattern
+    }
+}
+
+fn never(x: !) {
+    match x {} // ok
     match x {
         _ => {}, //~ ERROR unreachable pattern
     }
diff --git a/src/test/ui/pattern/usefulness/match-empty-exhaustive_patterns.stderr b/src/test/ui/pattern/usefulness/match-empty-exhaustive_patterns.stderr
index 1f6503e3e9c..9ec9d737e89 100644
--- a/src/test/ui/pattern/usefulness/match-empty-exhaustive_patterns.stderr
+++ b/src/test/ui/pattern/usefulness/match-empty-exhaustive_patterns.stderr
@@ -1,35 +1,47 @@
 error: unreachable pattern
-  --> $DIR/match-empty-exhaustive_patterns.rs:47:9
+  --> $DIR/match-empty-exhaustive_patterns.rs:48:9
    |
 LL |         _ => {},
    |         ^
    |
 note: the lint level is defined here
-  --> $DIR/match-empty-exhaustive_patterns.rs:3:9
+  --> $DIR/match-empty-exhaustive_patterns.rs:4:9
    |
 LL | #![deny(unreachable_patterns)]
    |         ^^^^^^^^^^^^^^^^^^^^
 
 error: unreachable pattern
-  --> $DIR/match-empty-exhaustive_patterns.rs:50:9
+  --> $DIR/match-empty-exhaustive_patterns.rs:51:9
    |
 LL |         _ if false => {},
    |         ^
 
 error: unreachable pattern
-  --> $DIR/match-empty-exhaustive_patterns.rs:57:9
+  --> $DIR/match-empty-exhaustive_patterns.rs:58:9
+   |
+LL |         _ => {},
+   |         ^
+
+error: unreachable pattern
+  --> $DIR/match-empty-exhaustive_patterns.rs:61:9
+   |
+LL |         _ if false => {},
+   |         ^
+
+error: unreachable pattern
+  --> $DIR/match-empty-exhaustive_patterns.rs:68:9
    |
 LL |         Some(_) => {}
    |         ^^^^^^^
 
 error: unreachable pattern
-  --> $DIR/match-empty-exhaustive_patterns.rs:61:9
+  --> $DIR/match-empty-exhaustive_patterns.rs:72:9
    |
 LL |         Some(_) => {}
    |         ^^^^^^^
 
 error[E0004]: non-exhaustive patterns: type `u8` is non-empty
-  --> $DIR/match-empty-exhaustive_patterns.rs:64:18
+  --> $DIR/match-empty-exhaustive_patterns.rs:75:18
    |
 LL |     match_empty!(0u8);
    |                  ^^^
@@ -38,7 +50,7 @@ LL |     match_empty!(0u8);
    = note: the matched value is of type `u8`
 
 error[E0004]: non-exhaustive patterns: type `NonEmptyStruct` is non-empty
-  --> $DIR/match-empty-exhaustive_patterns.rs:66:18
+  --> $DIR/match-empty-exhaustive_patterns.rs:77:18
    |
 LL | struct NonEmptyStruct(bool);
    | ---------------------------- `NonEmptyStruct` defined here
@@ -50,7 +62,7 @@ LL |     match_empty!(NonEmptyStruct(true));
    = note: the matched value is of type `NonEmptyStruct`
 
 error[E0004]: non-exhaustive patterns: type `NonEmptyUnion1` is non-empty
-  --> $DIR/match-empty-exhaustive_patterns.rs:68:18
+  --> $DIR/match-empty-exhaustive_patterns.rs:79:18
    |
 LL | / union NonEmptyUnion1 {
 LL | |     foo: (),
@@ -64,7 +76,7 @@ LL |       match_empty!((NonEmptyUnion1 { foo: () }));
    = note: the matched value is of type `NonEmptyUnion1`
 
 error[E0004]: non-exhaustive patterns: type `NonEmptyUnion2` is non-empty
-  --> $DIR/match-empty-exhaustive_patterns.rs:70:18
+  --> $DIR/match-empty-exhaustive_patterns.rs:81:18
    |
 LL | / union NonEmptyUnion2 {
 LL | |     foo: (),
@@ -79,7 +91,7 @@ LL |       match_empty!((NonEmptyUnion2 { foo: () }));
    = note: the matched value is of type `NonEmptyUnion2`
 
 error[E0004]: non-exhaustive patterns: `Foo(_)` not covered
-  --> $DIR/match-empty-exhaustive_patterns.rs:72:18
+  --> $DIR/match-empty-exhaustive_patterns.rs:83:18
    |
 LL | / enum NonEmptyEnum1 {
 LL | |     Foo(bool),
@@ -96,7 +108,7 @@ LL |       match_empty!(NonEmptyEnum1::Foo(true));
    = note: the matched value is of type `NonEmptyEnum1`
 
 error[E0004]: non-exhaustive patterns: `Foo(_)` and `Bar` not covered
-  --> $DIR/match-empty-exhaustive_patterns.rs:74:18
+  --> $DIR/match-empty-exhaustive_patterns.rs:85:18
    |
 LL | / enum NonEmptyEnum2 {
 LL | |     Foo(bool),
@@ -117,7 +129,7 @@ LL |       match_empty!(NonEmptyEnum2::Foo(true));
    = note: the matched value is of type `NonEmptyEnum2`
 
 error[E0004]: non-exhaustive patterns: `V1`, `V2`, `V3` and 2 more not covered
-  --> $DIR/match-empty-exhaustive_patterns.rs:76:18
+  --> $DIR/match-empty-exhaustive_patterns.rs:87:18
    |
 LL | / enum NonEmptyEnum5 {
 LL | |     V1, V2, V3, V4, V5,
@@ -131,7 +143,7 @@ LL |       match_empty!(NonEmptyEnum5::V1);
    = note: the matched value is of type `NonEmptyEnum5`
 
 error[E0004]: non-exhaustive patterns: `_` not covered
-  --> $DIR/match-empty-exhaustive_patterns.rs:79:18
+  --> $DIR/match-empty-exhaustive_patterns.rs:90:18
    |
 LL |     match_false!(0u8);
    |                  ^^^ pattern `_` not covered
@@ -140,7 +152,7 @@ LL |     match_false!(0u8);
    = note: the matched value is of type `u8`
 
 error[E0004]: non-exhaustive patterns: `NonEmptyStruct(_)` not covered
-  --> $DIR/match-empty-exhaustive_patterns.rs:81:18
+  --> $DIR/match-empty-exhaustive_patterns.rs:92:18
    |
 LL | struct NonEmptyStruct(bool);
    | ---------------------------- `NonEmptyStruct` defined here
@@ -152,7 +164,7 @@ LL |     match_false!(NonEmptyStruct(true));
    = note: the matched value is of type `NonEmptyStruct`
 
 error[E0004]: non-exhaustive patterns: `NonEmptyUnion1 { .. }` not covered
-  --> $DIR/match-empty-exhaustive_patterns.rs:83:18
+  --> $DIR/match-empty-exhaustive_patterns.rs:94:18
    |
 LL | / union NonEmptyUnion1 {
 LL | |     foo: (),
@@ -166,7 +178,7 @@ LL |       match_false!((NonEmptyUnion1 { foo: () }));
    = note: the matched value is of type `NonEmptyUnion1`
 
 error[E0004]: non-exhaustive patterns: `NonEmptyUnion2 { .. }` not covered
-  --> $DIR/match-empty-exhaustive_patterns.rs:85:18
+  --> $DIR/match-empty-exhaustive_patterns.rs:96:18
    |
 LL | / union NonEmptyUnion2 {
 LL | |     foo: (),
@@ -181,7 +193,7 @@ LL |       match_false!((NonEmptyUnion2 { foo: () }));
    = note: the matched value is of type `NonEmptyUnion2`
 
 error[E0004]: non-exhaustive patterns: `Foo(_)` not covered
-  --> $DIR/match-empty-exhaustive_patterns.rs:87:18
+  --> $DIR/match-empty-exhaustive_patterns.rs:98:18
    |
 LL | / enum NonEmptyEnum1 {
 LL | |     Foo(bool),
@@ -198,7 +210,7 @@ LL |       match_false!(NonEmptyEnum1::Foo(true));
    = note: the matched value is of type `NonEmptyEnum1`
 
 error[E0004]: non-exhaustive patterns: `Foo(_)` and `Bar` not covered
-  --> $DIR/match-empty-exhaustive_patterns.rs:89:18
+  --> $DIR/match-empty-exhaustive_patterns.rs:100:18
    |
 LL | / enum NonEmptyEnum2 {
 LL | |     Foo(bool),
@@ -219,7 +231,7 @@ LL |       match_false!(NonEmptyEnum2::Foo(true));
    = note: the matched value is of type `NonEmptyEnum2`
 
 error[E0004]: non-exhaustive patterns: `V1`, `V2`, `V3` and 2 more not covered
-  --> $DIR/match-empty-exhaustive_patterns.rs:91:18
+  --> $DIR/match-empty-exhaustive_patterns.rs:102:18
    |
 LL | / enum NonEmptyEnum5 {
 LL | |     V1, V2, V3, V4, V5,
@@ -232,6 +244,6 @@ LL |       match_false!(NonEmptyEnum5::V1);
    = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
    = note: the matched value is of type `NonEmptyEnum5`
 
-error: aborting due to 18 previous errors
+error: aborting due to 20 previous errors
 
 For more information about this error, try `rustc --explain E0004`.
diff --git a/src/test/ui/pattern/usefulness/match-empty.rs b/src/test/ui/pattern/usefulness/match-empty.rs
index f7577125d8a..609660a88f9 100644
--- a/src/test/ui/pattern/usefulness/match-empty.rs
+++ b/src/test/ui/pattern/usefulness/match-empty.rs
@@ -1,4 +1,5 @@
 #![feature(never_type)]
+#![feature(never_type_fallback)]
 #![deny(unreachable_patterns)]
 enum Foo {}
 
@@ -41,12 +42,25 @@ macro_rules! match_false {
 }
 
 fn foo(x: Foo) {
-    match_empty!(x); // ok
-    match_false!(x); // Not detected as unreachable nor exhaustive.
-    //~^ ERROR non-exhaustive patterns: `_` not covered
+    match x {} // ok
     match x {
         _ => {}, // Not detected as unreachable, see #55123.
     }
+    match x {
+    //~^ ERROR non-exhaustive patterns: `_` not covered
+        _ if false => {}, // Not detected as unreachable nor exhaustive.
+    }
+}
+
+fn never(x: !) {
+    match x {} // ok
+    match x {
+        _ => {}, // Not detected as unreachable.
+    }
+    match x {
+    //~^ ERROR non-exhaustive patterns: `_` not covered
+        _ if false => {}, // Not detected as unreachable nor exhaustive.
+    }
 }
 
 fn main() {
diff --git a/src/test/ui/pattern/usefulness/match-empty.stderr b/src/test/ui/pattern/usefulness/match-empty.stderr
index 08095f6e7fb..0218b6fda50 100644
--- a/src/test/ui/pattern/usefulness/match-empty.stderr
+++ b/src/test/ui/pattern/usefulness/match-empty.stderr
@@ -1,17 +1,26 @@
 error[E0004]: non-exhaustive patterns: `_` not covered
-  --> $DIR/match-empty.rs:45:18
+  --> $DIR/match-empty.rs:49:11
    |
 LL | enum Foo {}
    | ----------- `Foo` defined here
 ...
-LL |     match_false!(x); // Not detected as unreachable nor exhaustive.
-   |                  ^ pattern `_` not covered
+LL |     match x {
+   |           ^ pattern `_` 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[E0004]: non-exhaustive patterns: `_` not covered
+  --> $DIR/match-empty.rs:60:11
+   |
+LL |     match x {
+   |           ^ pattern `_` 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 `!`
+
 error[E0004]: non-exhaustive patterns: type `u8` is non-empty
-  --> $DIR/match-empty.rs:63:18
+  --> $DIR/match-empty.rs:77:18
    |
 LL |     match_empty!(0u8);
    |                  ^^^
@@ -20,7 +29,7 @@ LL |     match_empty!(0u8);
    = note: the matched value is of type `u8`
 
 error[E0004]: non-exhaustive patterns: type `NonEmptyStruct` is non-empty
-  --> $DIR/match-empty.rs:65:18
+  --> $DIR/match-empty.rs:79:18
    |
 LL | struct NonEmptyStruct(bool);
    | ---------------------------- `NonEmptyStruct` defined here
@@ -32,7 +41,7 @@ LL |     match_empty!(NonEmptyStruct(true));
    = note: the matched value is of type `NonEmptyStruct`
 
 error[E0004]: non-exhaustive patterns: type `NonEmptyUnion1` is non-empty
-  --> $DIR/match-empty.rs:67:18
+  --> $DIR/match-empty.rs:81:18
    |
 LL | / union NonEmptyUnion1 {
 LL | |     foo: (),
@@ -46,7 +55,7 @@ LL |       match_empty!((NonEmptyUnion1 { foo: () }));
    = note: the matched value is of type `NonEmptyUnion1`
 
 error[E0004]: non-exhaustive patterns: type `NonEmptyUnion2` is non-empty
-  --> $DIR/match-empty.rs:69:18
+  --> $DIR/match-empty.rs:83:18
    |
 LL | / union NonEmptyUnion2 {
 LL | |     foo: (),
@@ -61,7 +70,7 @@ LL |       match_empty!((NonEmptyUnion2 { foo: () }));
    = note: the matched value is of type `NonEmptyUnion2`
 
 error[E0004]: non-exhaustive patterns: `Foo(_)` not covered
-  --> $DIR/match-empty.rs:71:18
+  --> $DIR/match-empty.rs:85:18
    |
 LL | / enum NonEmptyEnum1 {
 LL | |     Foo(bool),
@@ -78,7 +87,7 @@ LL |       match_empty!(NonEmptyEnum1::Foo(true));
    = note: the matched value is of type `NonEmptyEnum1`
 
 error[E0004]: non-exhaustive patterns: `Foo(_)` and `Bar` not covered
-  --> $DIR/match-empty.rs:73:18
+  --> $DIR/match-empty.rs:87:18
    |
 LL | / enum NonEmptyEnum2 {
 LL | |     Foo(bool),
@@ -99,7 +108,7 @@ LL |       match_empty!(NonEmptyEnum2::Foo(true));
    = note: the matched value is of type `NonEmptyEnum2`
 
 error[E0004]: non-exhaustive patterns: `V1`, `V2`, `V3` and 2 more not covered
-  --> $DIR/match-empty.rs:75:18
+  --> $DIR/match-empty.rs:89:18
    |
 LL | / enum NonEmptyEnum5 {
 LL | |     V1, V2, V3, V4, V5,
@@ -113,7 +122,7 @@ LL |       match_empty!(NonEmptyEnum5::V1);
    = note: the matched value is of type `NonEmptyEnum5`
 
 error[E0004]: non-exhaustive patterns: `_` not covered
-  --> $DIR/match-empty.rs:78:18
+  --> $DIR/match-empty.rs:92:18
    |
 LL |     match_false!(0u8);
    |                  ^^^ pattern `_` not covered
@@ -122,7 +131,7 @@ LL |     match_false!(0u8);
    = note: the matched value is of type `u8`
 
 error[E0004]: non-exhaustive patterns: `NonEmptyStruct(_)` not covered
-  --> $DIR/match-empty.rs:80:18
+  --> $DIR/match-empty.rs:94:18
    |
 LL | struct NonEmptyStruct(bool);
    | ---------------------------- `NonEmptyStruct` defined here
@@ -134,7 +143,7 @@ LL |     match_false!(NonEmptyStruct(true));
    = note: the matched value is of type `NonEmptyStruct`
 
 error[E0004]: non-exhaustive patterns: `NonEmptyUnion1 { .. }` not covered
-  --> $DIR/match-empty.rs:82:18
+  --> $DIR/match-empty.rs:96:18
    |
 LL | / union NonEmptyUnion1 {
 LL | |     foo: (),
@@ -148,7 +157,7 @@ LL |       match_false!((NonEmptyUnion1 { foo: () }));
    = note: the matched value is of type `NonEmptyUnion1`
 
 error[E0004]: non-exhaustive patterns: `NonEmptyUnion2 { .. }` not covered
-  --> $DIR/match-empty.rs:84:18
+  --> $DIR/match-empty.rs:98:18
    |
 LL | / union NonEmptyUnion2 {
 LL | |     foo: (),
@@ -163,7 +172,7 @@ LL |       match_false!((NonEmptyUnion2 { foo: () }));
    = note: the matched value is of type `NonEmptyUnion2`
 
 error[E0004]: non-exhaustive patterns: `Foo(_)` not covered
-  --> $DIR/match-empty.rs:86:18
+  --> $DIR/match-empty.rs:100:18
    |
 LL | / enum NonEmptyEnum1 {
 LL | |     Foo(bool),
@@ -180,7 +189,7 @@ LL |       match_false!(NonEmptyEnum1::Foo(true));
    = note: the matched value is of type `NonEmptyEnum1`
 
 error[E0004]: non-exhaustive patterns: `Foo(_)` and `Bar` not covered
-  --> $DIR/match-empty.rs:88:18
+  --> $DIR/match-empty.rs:102:18
    |
 LL | / enum NonEmptyEnum2 {
 LL | |     Foo(bool),
@@ -201,7 +210,7 @@ LL |       match_false!(NonEmptyEnum2::Foo(true));
    = note: the matched value is of type `NonEmptyEnum2`
 
 error[E0004]: non-exhaustive patterns: `V1`, `V2`, `V3` and 2 more not covered
-  --> $DIR/match-empty.rs:90:18
+  --> $DIR/match-empty.rs:104:18
    |
 LL | / enum NonEmptyEnum5 {
 LL | |     V1, V2, V3, V4, V5,
@@ -214,6 +223,6 @@ LL |       match_false!(NonEmptyEnum5::V1);
    = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
    = note: the matched value is of type `NonEmptyEnum5`
 
-error: aborting due to 15 previous errors
+error: aborting due to 16 previous errors
 
 For more information about this error, try `rustc --explain E0004`.