Skip to content

Commit

Permalink
Add a test for foreign empty enums
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadrieril committed Nov 16, 2020
1 parent 36e3409 commit 69821cf
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 48 deletions.
2 changes: 2 additions & 0 deletions src/test/ui/pattern/usefulness/auxiliary/empty.rs
@@ -0,0 +1,2 @@
#![crate_type = "rlib"]
pub enum EmptyForeignEnum {}
20 changes: 17 additions & 3 deletions src/test/ui/pattern/usefulness/match-empty-exhaustive_patterns.rs
@@ -1,8 +1,12 @@
// aux-build:empty.rs
#![feature(never_type)]
#![feature(never_type_fallback)]
#![feature(exhaustive_patterns)]
#![deny(unreachable_patterns)]
enum Foo {}

extern crate empty;

enum EmptyEnum {}

struct NonEmptyStruct(bool); //~ `NonEmptyStruct` defined here
union NonEmptyUnion1 { //~ `NonEmptyUnion1` defined here
Expand Down Expand Up @@ -42,7 +46,17 @@ macro_rules! match_false {
};
}

fn foo(x: Foo) {
fn empty_enum(x: EmptyEnum) {
match x {} // ok
match x {
_ => {}, //~ ERROR unreachable pattern
}
match x {
_ if false => {}, //~ ERROR unreachable pattern
}
}

fn empty_foreign_enum(x: empty::EmptyForeignEnum) {
match x {} // ok
match x {
_ => {}, //~ ERROR unreachable pattern
Expand All @@ -67,7 +81,7 @@ fn main() {
None => {}
Some(_) => {} //~ ERROR unreachable pattern
}
match None::<Foo> {
match None::<EmptyEnum> {
None => {}
Some(_) => {} //~ ERROR unreachable pattern
}
Expand Down
@@ -1,47 +1,59 @@
error: unreachable pattern
--> $DIR/match-empty-exhaustive_patterns.rs:48:9
--> $DIR/match-empty-exhaustive_patterns.rs:52:9
|
LL | _ => {},
| ^
|
note: the lint level is defined here
--> $DIR/match-empty-exhaustive_patterns.rs:4:9
--> $DIR/match-empty-exhaustive_patterns.rs:5:9
|
LL | #![deny(unreachable_patterns)]
| ^^^^^^^^^^^^^^^^^^^^

error: unreachable pattern
--> $DIR/match-empty-exhaustive_patterns.rs:51:9
--> $DIR/match-empty-exhaustive_patterns.rs:55:9
|
LL | _ if false => {},
| ^

error: unreachable pattern
--> $DIR/match-empty-exhaustive_patterns.rs:58:9
--> $DIR/match-empty-exhaustive_patterns.rs:62:9
|
LL | _ => {},
| ^

error: unreachable pattern
--> $DIR/match-empty-exhaustive_patterns.rs:61:9
--> $DIR/match-empty-exhaustive_patterns.rs:65:9
|
LL | _ if false => {},
| ^

error: unreachable pattern
--> $DIR/match-empty-exhaustive_patterns.rs:68:9
--> $DIR/match-empty-exhaustive_patterns.rs:72:9
|
LL | _ => {},
| ^

error: unreachable pattern
--> $DIR/match-empty-exhaustive_patterns.rs:75:9
|
LL | _ if false => {},
| ^

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

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

error[E0004]: non-exhaustive patterns: type `u8` is non-empty
--> $DIR/match-empty-exhaustive_patterns.rs:75:18
--> $DIR/match-empty-exhaustive_patterns.rs:89:18
|
LL | match_empty!(0u8);
| ^^^
Expand All @@ -50,7 +62,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:77:18
--> $DIR/match-empty-exhaustive_patterns.rs:91:18
|
LL | struct NonEmptyStruct(bool);
| ---------------------------- `NonEmptyStruct` defined here
Expand All @@ -62,7 +74,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:79:18
--> $DIR/match-empty-exhaustive_patterns.rs:93:18
|
LL | / union NonEmptyUnion1 {
LL | | foo: (),
Expand All @@ -76,7 +88,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:81:18
--> $DIR/match-empty-exhaustive_patterns.rs:95:18
|
LL | / union NonEmptyUnion2 {
LL | | foo: (),
Expand All @@ -91,7 +103,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:83:18
--> $DIR/match-empty-exhaustive_patterns.rs:97:18
|
LL | / enum NonEmptyEnum1 {
LL | | Foo(bool),
Expand All @@ -108,7 +120,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:85:18
--> $DIR/match-empty-exhaustive_patterns.rs:99:18
|
LL | / enum NonEmptyEnum2 {
LL | | Foo(bool),
Expand All @@ -129,7 +141,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:87:18
--> $DIR/match-empty-exhaustive_patterns.rs:101:18
|
LL | / enum NonEmptyEnum5 {
LL | | V1, V2, V3, V4, V5,
Expand All @@ -143,7 +155,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:90:18
--> $DIR/match-empty-exhaustive_patterns.rs:104:18
|
LL | match_false!(0u8);
| ^^^ pattern `_` not covered
Expand All @@ -152,7 +164,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:92:18
--> $DIR/match-empty-exhaustive_patterns.rs:106:18
|
LL | struct NonEmptyStruct(bool);
| ---------------------------- `NonEmptyStruct` defined here
Expand All @@ -164,7 +176,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:94:18
--> $DIR/match-empty-exhaustive_patterns.rs:108:18
|
LL | / union NonEmptyUnion1 {
LL | | foo: (),
Expand All @@ -178,7 +190,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:96:18
--> $DIR/match-empty-exhaustive_patterns.rs:110:18
|
LL | / union NonEmptyUnion2 {
LL | | foo: (),
Expand All @@ -193,7 +205,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:98:18
--> $DIR/match-empty-exhaustive_patterns.rs:112:18
|
LL | / enum NonEmptyEnum1 {
LL | | Foo(bool),
Expand All @@ -210,7 +222,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:100:18
--> $DIR/match-empty-exhaustive_patterns.rs:114:18
|
LL | / enum NonEmptyEnum2 {
LL | | Foo(bool),
Expand All @@ -231,7 +243,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:102:18
--> $DIR/match-empty-exhaustive_patterns.rs:116:18
|
LL | / enum NonEmptyEnum5 {
LL | | V1, V2, V3, V4, V5,
Expand All @@ -244,6 +256,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 20 previous errors
error: aborting due to 22 previous errors

For more information about this error, try `rustc --explain E0004`.
20 changes: 17 additions & 3 deletions src/test/ui/pattern/usefulness/match-empty.rs
@@ -1,7 +1,11 @@
// aux-build:empty.rs
#![feature(never_type)]
#![feature(never_type_fallback)]
#![deny(unreachable_patterns)]
enum Foo {}

extern crate empty;

enum EmptyEnum {}

struct NonEmptyStruct(bool); //~ `NonEmptyStruct` defined here
union NonEmptyUnion1 { //~ `NonEmptyUnion1` defined here
Expand Down Expand Up @@ -41,7 +45,17 @@ macro_rules! match_false {
};
}

fn foo(x: Foo) {
fn empty_enum(x: EmptyEnum) {
match x {} // ok
match x {
_ => {}, //~ ERROR unreachable pattern
}
match x {
_ if false => {}, //~ ERROR unreachable pattern
}
}

fn empty_foreign_enum(x: empty::EmptyForeignEnum) {
match x {} // ok
match x {
_ => {}, //~ ERROR unreachable pattern
Expand All @@ -67,7 +81,7 @@ fn main() {
None => {}
Some(_) => {}
}
match None::<Foo> {
match None::<EmptyEnum> {
None => {}
Some(_) => {}
}
Expand Down

0 comments on commit 69821cf

Please sign in to comment.