Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadrieril committed Dec 4, 2019
1 parent 5628d4a commit 2099dd1
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 16 deletions.
11 changes: 11 additions & 0 deletions src/test/ui/pattern/usefulness/match-empty-exhaustive_patterns.rs
Expand Up @@ -4,6 +4,13 @@
enum Foo {}

struct NonEmptyStruct(bool); //~ `NonEmptyStruct` defined here
union NonEmptyUnion1 {
foo: (),
}
union NonEmptyUnion2 {
foo: (),
bar: (),
}
enum NonEmptyEnum1 { //~ `NonEmptyEnum1` defined here
Foo(bool), //~ variant not covered
}
Expand Down Expand Up @@ -36,6 +43,10 @@ fn main() {
//~^ ERROR type `u8` is non-empty
match NonEmptyStruct(true) {}
//~^ ERROR pattern `NonEmptyStruct` of type `NonEmptyStruct` is not handled
match (NonEmptyUnion1 { foo: () }) {}
//~^ ERROR pattern `NonEmptyUnion1` of type `NonEmptyUnion1` is not handled
match (NonEmptyUnion2 { foo: () }) {}
//~^ ERROR pattern `NonEmptyUnion2` of type `NonEmptyUnion2` is not handled
match NonEmptyEnum1::Foo(true) {}
//~^ ERROR pattern `Foo` of type `NonEmptyEnum1` is not handled
match NonEmptyEnum2::Foo(true) {}
Expand Down
@@ -1,5 +1,5 @@
error: unreachable pattern
--> $DIR/match-empty-exhaustive_patterns.rs:21:9
--> $DIR/match-empty-exhaustive_patterns.rs:28:9
|
LL | _ => {},
| ^
Expand All @@ -11,27 +11,27 @@ LL | #![deny(unreachable_patterns)]
| ^^^^^^^^^^^^^^^^^^^^

error: unreachable pattern
--> $DIR/match-empty-exhaustive_patterns.rs:28:9
--> $DIR/match-empty-exhaustive_patterns.rs:35:9
|
LL | Some(_) => {}
| ^^^^^^^

error: unreachable pattern
--> $DIR/match-empty-exhaustive_patterns.rs:32:9
--> $DIR/match-empty-exhaustive_patterns.rs:39:9
|
LL | Some(_) => {}
| ^^^^^^^

error[E0004]: non-exhaustive patterns: type `u8` is non-empty
--> $DIR/match-empty-exhaustive_patterns.rs:35:11
--> $DIR/match-empty-exhaustive_patterns.rs:42:11
|
LL | match 0u8 {}
| ^^^
|
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms

error[E0004]: non-exhaustive patterns: pattern `NonEmptyStruct` of type `NonEmptyStruct` is not handled
--> $DIR/match-empty-exhaustive_patterns.rs:37:11
--> $DIR/match-empty-exhaustive_patterns.rs:44:11
|
LL | struct NonEmptyStruct(bool);
| ----------------------------
Expand All @@ -44,8 +44,41 @@ LL | match NonEmptyStruct(true) {}
|
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms

error[E0004]: non-exhaustive patterns: pattern `NonEmptyUnion1` of type `NonEmptyUnion1` is not handled
--> $DIR/match-empty-exhaustive_patterns.rs:46:11
|
LL | union NonEmptyUnion1 {
| - -------------- variant not covered
| _|
| |
LL | | foo: (),
LL | | }
| |_- `NonEmptyUnion1` defined here
...
LL | match (NonEmptyUnion1 { foo: () }) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms

error[E0004]: non-exhaustive patterns: pattern `NonEmptyUnion2` of type `NonEmptyUnion2` is not handled
--> $DIR/match-empty-exhaustive_patterns.rs:48:11
|
LL | union NonEmptyUnion2 {
| - -------------- variant not covered
| _|
| |
LL | | foo: (),
LL | | bar: (),
LL | | }
| |_- `NonEmptyUnion2` defined here
...
LL | match (NonEmptyUnion2 { foo: () }) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms

error[E0004]: non-exhaustive patterns: pattern `Foo` of type `NonEmptyEnum1` is not handled
--> $DIR/match-empty-exhaustive_patterns.rs:39:11
--> $DIR/match-empty-exhaustive_patterns.rs:50:11
|
LL | / enum NonEmptyEnum1 {
LL | | Foo(bool),
Expand All @@ -59,7 +92,7 @@ LL | match NonEmptyEnum1::Foo(true) {}
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms

error[E0004]: non-exhaustive patterns: multiple patterns of type `NonEmptyEnum2` are not handled
--> $DIR/match-empty-exhaustive_patterns.rs:41:11
--> $DIR/match-empty-exhaustive_patterns.rs:52:11
|
LL | / enum NonEmptyEnum2 {
LL | | Foo(bool),
Expand All @@ -75,7 +108,7 @@ LL | match NonEmptyEnum2::Foo(true) {}
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms

error[E0004]: non-exhaustive patterns: multiple patterns of type `NonEmptyEnum5` are not handled
--> $DIR/match-empty-exhaustive_patterns.rs:43:11
--> $DIR/match-empty-exhaustive_patterns.rs:54:11
|
LL | / enum NonEmptyEnum5 {
LL | | V1, V2, V3, V4, V5,
Expand All @@ -87,6 +120,6 @@ LL | match NonEmptyEnum5::V1 {}
|
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms

error: aborting due to 8 previous errors
error: aborting due to 10 previous errors

For more information about this error, try `rustc --explain E0004`.
13 changes: 12 additions & 1 deletion src/test/ui/pattern/usefulness/match-empty.rs
Expand Up @@ -3,6 +3,13 @@
enum Foo {}

struct NonEmptyStruct(bool); //~ `NonEmptyStruct` defined here
union NonEmptyUnion1 {
foo: (),
}
union NonEmptyUnion2 {
foo: (),
bar: (),
}
enum NonEmptyEnum1 { //~ `NonEmptyEnum1` defined here
Foo(bool), //~ variant not covered
}
Expand All @@ -20,7 +27,7 @@ fn foo1(x: Foo) {

fn foo2(x: Foo) {
match x {
_ => {}, // FIXME: should be unreachable
_ => {}, // Not detected as unreachable, see #55123.
}
}

Expand All @@ -39,6 +46,10 @@ fn main() {
//~^ ERROR type `u8` is non-empty
match NonEmptyStruct(true) {}
//~^ ERROR pattern `NonEmptyStruct` of type `NonEmptyStruct` is not handled
match (NonEmptyUnion1 { foo: () }) {}
//~^ ERROR pattern `NonEmptyUnion1` of type `NonEmptyUnion1` is not handled
match (NonEmptyUnion2 { foo: () }) {}
//~^ ERROR pattern `NonEmptyUnion2` of type `NonEmptyUnion2` is not handled
match NonEmptyEnum1::Foo(true) {}
//~^ ERROR pattern `Foo` of type `NonEmptyEnum1` is not handled
match NonEmptyEnum2::Foo(true) {}
Expand Down
45 changes: 39 additions & 6 deletions src/test/ui/pattern/usefulness/match-empty.stderr
@@ -1,13 +1,13 @@
error[E0004]: non-exhaustive patterns: type `u8` is non-empty
--> $DIR/match-empty.rs:38:11
--> $DIR/match-empty.rs:45:11
|
LL | match 0u8 {}
| ^^^
|
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms

error[E0004]: non-exhaustive patterns: pattern `NonEmptyStruct` of type `NonEmptyStruct` is not handled
--> $DIR/match-empty.rs:40:11
--> $DIR/match-empty.rs:47:11
|
LL | struct NonEmptyStruct(bool);
| ----------------------------
Expand All @@ -20,8 +20,41 @@ LL | match NonEmptyStruct(true) {}
|
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms

error[E0004]: non-exhaustive patterns: pattern `NonEmptyUnion1` of type `NonEmptyUnion1` is not handled
--> $DIR/match-empty.rs:49:11
|
LL | union NonEmptyUnion1 {
| - -------------- variant not covered
| _|
| |
LL | | foo: (),
LL | | }
| |_- `NonEmptyUnion1` defined here
...
LL | match (NonEmptyUnion1 { foo: () }) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms

error[E0004]: non-exhaustive patterns: pattern `NonEmptyUnion2` of type `NonEmptyUnion2` is not handled
--> $DIR/match-empty.rs:51:11
|
LL | union NonEmptyUnion2 {
| - -------------- variant not covered
| _|
| |
LL | | foo: (),
LL | | bar: (),
LL | | }
| |_- `NonEmptyUnion2` defined here
...
LL | match (NonEmptyUnion2 { foo: () }) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms

error[E0004]: non-exhaustive patterns: pattern `Foo` of type `NonEmptyEnum1` is not handled
--> $DIR/match-empty.rs:42:11
--> $DIR/match-empty.rs:53:11
|
LL | / enum NonEmptyEnum1 {
LL | | Foo(bool),
Expand All @@ -35,7 +68,7 @@ LL | match NonEmptyEnum1::Foo(true) {}
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms

error[E0004]: non-exhaustive patterns: multiple patterns of type `NonEmptyEnum2` are not handled
--> $DIR/match-empty.rs:44:11
--> $DIR/match-empty.rs:55:11
|
LL | / enum NonEmptyEnum2 {
LL | | Foo(bool),
Expand All @@ -51,7 +84,7 @@ LL | match NonEmptyEnum2::Foo(true) {}
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms

error[E0004]: non-exhaustive patterns: multiple patterns of type `NonEmptyEnum5` are not handled
--> $DIR/match-empty.rs:46:11
--> $DIR/match-empty.rs:57:11
|
LL | / enum NonEmptyEnum5 {
LL | | V1, V2, V3, V4, V5,
Expand All @@ -63,6 +96,6 @@ LL | match NonEmptyEnum5::V1 {}
|
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms

error: aborting due to 5 previous errors
error: aborting due to 7 previous errors

For more information about this error, try `rustc --explain E0004`.

0 comments on commit 2099dd1

Please sign in to comment.