Add tests

This commit is contained in:
Nadrieril 2019-12-03 15:57:04 +00:00
parent c0f3c06c6d
commit 5a3b7d2055
4 changed files with 313 additions and 66 deletions

View File

@ -22,11 +22,27 @@ enum NonEmptyEnum5 { //~ `NonEmptyEnum5` defined here
V1, V2, V3, V4, V5,
}
macro_rules! match_empty {
($e:expr) => {
match $e {}
};
}
macro_rules! match_false {
($e:expr) => {
match $e {
_ if false => {}
}
};
}
fn foo(x: Foo) {
match x {} // ok
match_empty!(x); // ok
match x {
_ => {}, //~ ERROR unreachable pattern
}
match x {
_ if false => {}, //~ ERROR unreachable pattern
}
}
fn main() {
@ -39,18 +55,33 @@ fn main() {
Some(_) => {} //~ ERROR unreachable pattern
}
match 0u8 {}
match_empty!(0u8);
//~^ ERROR type `u8` is non-empty
match NonEmptyStruct(true) {}
match_empty!(NonEmptyStruct(true));
//~^ ERROR type `NonEmptyStruct` is non-empty
match (NonEmptyUnion1 { foo: () }) {}
match_empty!((NonEmptyUnion1 { foo: () }));
//~^ ERROR type `NonEmptyUnion1` is non-empty
match (NonEmptyUnion2 { foo: () }) {}
match_empty!((NonEmptyUnion2 { foo: () }));
//~^ ERROR type `NonEmptyUnion2` is non-empty
match NonEmptyEnum1::Foo(true) {}
match_empty!(NonEmptyEnum1::Foo(true));
//~^ ERROR pattern `Foo` of type `NonEmptyEnum1` is not handled
match NonEmptyEnum2::Foo(true) {}
match_empty!(NonEmptyEnum2::Foo(true));
//~^ ERROR multiple patterns of type `NonEmptyEnum2` are not handled
match NonEmptyEnum5::V1 {}
match_empty!(NonEmptyEnum5::V1);
//~^ ERROR multiple patterns of type `NonEmptyEnum5` are not handled
match_false!(0u8);
//~^ ERROR `_` not covered
match_false!(NonEmptyStruct(true));
//~^ ERROR `_` not covered
match_false!((NonEmptyUnion1 { foo: () }));
//~^ ERROR `_` not covered
match_false!((NonEmptyUnion2 { foo: () }));
//~^ ERROR `_` not covered
match_false!(NonEmptyEnum1::Foo(true));
//~^ ERROR `_` not covered
match_false!(NonEmptyEnum2::Foo(true));
//~^ ERROR `_` not covered
match_false!(NonEmptyEnum5::V1);
//~^ ERROR `_` not covered
}

View File

@ -1,5 +1,5 @@
error: unreachable pattern
--> $DIR/match-empty-exhaustive_patterns.rs:28:9
--> $DIR/match-empty-exhaustive_patterns.rs:41:9
|
LL | _ => {},
| ^
@ -11,51 +11,57 @@ LL | #![deny(unreachable_patterns)]
| ^^^^^^^^^^^^^^^^^^^^
error: unreachable pattern
--> $DIR/match-empty-exhaustive_patterns.rs:35:9
--> $DIR/match-empty-exhaustive_patterns.rs:44:9
|
LL | _ if false => {},
| ^
error: unreachable pattern
--> $DIR/match-empty-exhaustive_patterns.rs:51:9
|
LL | Some(_) => {}
| ^^^^^^^
error: unreachable pattern
--> $DIR/match-empty-exhaustive_patterns.rs:39:9
--> $DIR/match-empty-exhaustive_patterns.rs:55:9
|
LL | Some(_) => {}
| ^^^^^^^
error[E0004]: non-exhaustive patterns: type `u8` is non-empty
--> $DIR/match-empty-exhaustive_patterns.rs:42:11
--> $DIR/match-empty-exhaustive_patterns.rs:58:18
|
LL | match 0u8 {}
| ^^^
LL | match_empty!(0u8);
| ^^^
|
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
error[E0004]: non-exhaustive patterns: type `NonEmptyStruct` is non-empty
--> $DIR/match-empty-exhaustive_patterns.rs:44:11
--> $DIR/match-empty-exhaustive_patterns.rs:60:18
|
LL | match NonEmptyStruct(true) {}
| ^^^^^^^^^^^^^^^^^^^^
LL | match_empty!(NonEmptyStruct(true));
| ^^^^^^^^^^^^^^^^^^^^
|
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
error[E0004]: non-exhaustive patterns: type `NonEmptyUnion1` is non-empty
--> $DIR/match-empty-exhaustive_patterns.rs:46:11
--> $DIR/match-empty-exhaustive_patterns.rs:62:18
|
LL | match (NonEmptyUnion1 { foo: () }) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | match_empty!((NonEmptyUnion1 { foo: () }));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
error[E0004]: non-exhaustive patterns: type `NonEmptyUnion2` is non-empty
--> $DIR/match-empty-exhaustive_patterns.rs:48:11
--> $DIR/match-empty-exhaustive_patterns.rs:64:18
|
LL | match (NonEmptyUnion2 { foo: () }) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | match_empty!((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:50:11
--> $DIR/match-empty-exhaustive_patterns.rs:66:18
|
LL | / enum NonEmptyEnum1 {
LL | | Foo(bool),
@ -63,13 +69,13 @@ LL | | Foo(bool),
LL | | }
| |_- `NonEmptyEnum1` defined here
...
LL | match NonEmptyEnum1::Foo(true) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^
LL | match_empty!(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:52:11
--> $DIR/match-empty-exhaustive_patterns.rs:68:18
|
LL | / enum NonEmptyEnum2 {
LL | | Foo(bool),
@ -79,24 +85,110 @@ LL | | Bar,
LL | | }
| |_- `NonEmptyEnum2` defined here
...
LL | match NonEmptyEnum2::Foo(true) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^
LL | match_empty!(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:54:11
--> $DIR/match-empty-exhaustive_patterns.rs:70:18
|
LL | / enum NonEmptyEnum5 {
LL | | V1, V2, V3, V4, V5,
LL | | }
| |_- `NonEmptyEnum5` defined here
...
LL | match NonEmptyEnum5::V1 {}
| ^^^^^^^^^^^^^^^^^
LL | match_empty!(NonEmptyEnum5::V1);
| ^^^^^^^^^^^^^^^^^
|
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
error: aborting due to 10 previous errors
error[E0004]: non-exhaustive patterns: `_` not covered
--> $DIR/match-empty-exhaustive_patterns.rs:73:18
|
LL | match_false!(0u8);
| ^^^ pattern `_` not covered
|
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
error[E0004]: non-exhaustive patterns: `_` not covered
--> $DIR/match-empty-exhaustive_patterns.rs:75:18
|
LL | struct NonEmptyStruct(bool);
| ---------------------------- `NonEmptyStruct` defined here
...
LL | match_false!(NonEmptyStruct(true));
| ^^^^^^^^^^^^^^^^^^^^ pattern `_` not covered
|
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
error[E0004]: non-exhaustive patterns: `_` not covered
--> $DIR/match-empty-exhaustive_patterns.rs:77:18
|
LL | / union NonEmptyUnion1 {
LL | | foo: (),
LL | | }
| |_- `NonEmptyUnion1` defined here
...
LL | match_false!((NonEmptyUnion1 { foo: () }));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pattern `_` not covered
|
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
error[E0004]: non-exhaustive patterns: `_` not covered
--> $DIR/match-empty-exhaustive_patterns.rs:79:18
|
LL | / union NonEmptyUnion2 {
LL | | foo: (),
LL | | bar: (),
LL | | }
| |_- `NonEmptyUnion2` defined here
...
LL | match_false!((NonEmptyUnion2 { foo: () }));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pattern `_` not covered
|
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
error[E0004]: non-exhaustive patterns: `_` not covered
--> $DIR/match-empty-exhaustive_patterns.rs:81:18
|
LL | / enum NonEmptyEnum1 {
LL | | Foo(bool),
LL | | }
| |_- `NonEmptyEnum1` defined here
...
LL | match_false!(NonEmptyEnum1::Foo(true));
| ^^^^^^^^^^^^^^^^^^^^^^^^ pattern `_` not covered
|
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
error[E0004]: non-exhaustive patterns: `_` not covered
--> $DIR/match-empty-exhaustive_patterns.rs:83:18
|
LL | / enum NonEmptyEnum2 {
LL | | Foo(bool),
LL | | Bar,
LL | | }
| |_- `NonEmptyEnum2` defined here
...
LL | match_false!(NonEmptyEnum2::Foo(true));
| ^^^^^^^^^^^^^^^^^^^^^^^^ pattern `_` not covered
|
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
error[E0004]: non-exhaustive patterns: `_` not covered
--> $DIR/match-empty-exhaustive_patterns.rs:85:18
|
LL | / enum NonEmptyEnum5 {
LL | | V1, V2, V3, V4, V5,
LL | | }
| |_- `NonEmptyEnum5` defined here
...
LL | match_false!(NonEmptyEnum5::V1);
| ^^^^^^^^^^^^^^^^^ pattern `_` not covered
|
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
error: aborting due to 18 previous errors
For more information about this error, try `rustc --explain E0004`.

View File

@ -21,11 +21,23 @@ enum NonEmptyEnum5 { //~ `NonEmptyEnum5` defined here
V1, V2, V3, V4, V5,
}
fn foo1(x: Foo) {
match x {} // ok
macro_rules! match_empty {
($e:expr) => {
match $e {}
};
}
macro_rules! match_false {
($e:expr) => {
match $e {
_ if false => {}
}
};
}
fn foo2(x: Foo) {
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 {
_ => {}, // Not detected as unreachable, see #55123.
}
@ -42,18 +54,33 @@ fn main() {
Some(_) => {}
}
match 0u8 {}
match_empty!(0u8);
//~^ ERROR type `u8` is non-empty
match NonEmptyStruct(true) {}
match_empty!(NonEmptyStruct(true));
//~^ ERROR type `NonEmptyStruct` is non-empty
match (NonEmptyUnion1 { foo: () }) {}
match_empty!((NonEmptyUnion1 { foo: () }));
//~^ ERROR type `NonEmptyUnion1` is non-empty
match (NonEmptyUnion2 { foo: () }) {}
match_empty!((NonEmptyUnion2 { foo: () }));
//~^ ERROR type `NonEmptyUnion2` is non-empty
match NonEmptyEnum1::Foo(true) {}
match_empty!(NonEmptyEnum1::Foo(true));
//~^ ERROR pattern `Foo` of type `NonEmptyEnum1` is not handled
match NonEmptyEnum2::Foo(true) {}
match_empty!(NonEmptyEnum2::Foo(true));
//~^ ERROR multiple patterns of type `NonEmptyEnum2` are not handled
match NonEmptyEnum5::V1 {}
match_empty!(NonEmptyEnum5::V1);
//~^ ERROR multiple patterns of type `NonEmptyEnum5` are not handled
match_false!(0u8);
//~^ ERROR `_` not covered
match_false!(NonEmptyStruct(true));
//~^ ERROR `_` not covered
match_false!((NonEmptyUnion1 { foo: () }));
//~^ ERROR `_` not covered
match_false!((NonEmptyUnion2 { foo: () }));
//~^ ERROR `_` not covered
match_false!(NonEmptyEnum1::Foo(true));
//~^ ERROR `_` not covered
match_false!(NonEmptyEnum2::Foo(true));
//~^ ERROR `_` not covered
match_false!(NonEmptyEnum5::V1);
//~^ ERROR `_` not covered
}

View File

@ -1,37 +1,48 @@
error[E0004]: non-exhaustive patterns: type `u8` is non-empty
--> $DIR/match-empty.rs:45:11
error[E0004]: non-exhaustive patterns: `_` not covered
--> $DIR/match-empty.rs:39:18
|
LL | match 0u8 {}
| ^^^
LL | enum Foo {}
| ----------- `Foo` defined here
...
LL | match_false!(x); // Not detected as unreachable nor exhaustive.
| ^ pattern `_` not covered
|
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
error[E0004]: non-exhaustive patterns: type `u8` is non-empty
--> $DIR/match-empty.rs:57:18
|
LL | match_empty!(0u8);
| ^^^
|
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
error[E0004]: non-exhaustive patterns: type `NonEmptyStruct` is non-empty
--> $DIR/match-empty.rs:47:11
--> $DIR/match-empty.rs:59:18
|
LL | match NonEmptyStruct(true) {}
| ^^^^^^^^^^^^^^^^^^^^
LL | match_empty!(NonEmptyStruct(true));
| ^^^^^^^^^^^^^^^^^^^^
|
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
error[E0004]: non-exhaustive patterns: type `NonEmptyUnion1` is non-empty
--> $DIR/match-empty.rs:49:11
--> $DIR/match-empty.rs:61:18
|
LL | match (NonEmptyUnion1 { foo: () }) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | match_empty!((NonEmptyUnion1 { foo: () }));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
error[E0004]: non-exhaustive patterns: type `NonEmptyUnion2` is non-empty
--> $DIR/match-empty.rs:51:11
--> $DIR/match-empty.rs:63:18
|
LL | match (NonEmptyUnion2 { foo: () }) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | match_empty!((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:53:11
--> $DIR/match-empty.rs:65:18
|
LL | / enum NonEmptyEnum1 {
LL | | Foo(bool),
@ -39,13 +50,13 @@ LL | | Foo(bool),
LL | | }
| |_- `NonEmptyEnum1` defined here
...
LL | match NonEmptyEnum1::Foo(true) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^
LL | match_empty!(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:55:11
--> $DIR/match-empty.rs:67:18
|
LL | / enum NonEmptyEnum2 {
LL | | Foo(bool),
@ -55,24 +66,110 @@ LL | | Bar,
LL | | }
| |_- `NonEmptyEnum2` defined here
...
LL | match NonEmptyEnum2::Foo(true) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^
LL | match_empty!(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:57:11
--> $DIR/match-empty.rs:69:18
|
LL | / enum NonEmptyEnum5 {
LL | | V1, V2, V3, V4, V5,
LL | | }
| |_- `NonEmptyEnum5` defined here
...
LL | match NonEmptyEnum5::V1 {}
| ^^^^^^^^^^^^^^^^^
LL | match_empty!(NonEmptyEnum5::V1);
| ^^^^^^^^^^^^^^^^^
|
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
error: aborting due to 7 previous errors
error[E0004]: non-exhaustive patterns: `_` not covered
--> $DIR/match-empty.rs:72:18
|
LL | match_false!(0u8);
| ^^^ pattern `_` not covered
|
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
error[E0004]: non-exhaustive patterns: `_` not covered
--> $DIR/match-empty.rs:74:18
|
LL | struct NonEmptyStruct(bool);
| ---------------------------- `NonEmptyStruct` defined here
...
LL | match_false!(NonEmptyStruct(true));
| ^^^^^^^^^^^^^^^^^^^^ pattern `_` not covered
|
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
error[E0004]: non-exhaustive patterns: `_` not covered
--> $DIR/match-empty.rs:76:18
|
LL | / union NonEmptyUnion1 {
LL | | foo: (),
LL | | }
| |_- `NonEmptyUnion1` defined here
...
LL | match_false!((NonEmptyUnion1 { foo: () }));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pattern `_` not covered
|
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
error[E0004]: non-exhaustive patterns: `_` not covered
--> $DIR/match-empty.rs:78:18
|
LL | / union NonEmptyUnion2 {
LL | | foo: (),
LL | | bar: (),
LL | | }
| |_- `NonEmptyUnion2` defined here
...
LL | match_false!((NonEmptyUnion2 { foo: () }));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pattern `_` not covered
|
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
error[E0004]: non-exhaustive patterns: `_` not covered
--> $DIR/match-empty.rs:80:18
|
LL | / enum NonEmptyEnum1 {
LL | | Foo(bool),
LL | | }
| |_- `NonEmptyEnum1` defined here
...
LL | match_false!(NonEmptyEnum1::Foo(true));
| ^^^^^^^^^^^^^^^^^^^^^^^^ pattern `_` not covered
|
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
error[E0004]: non-exhaustive patterns: `_` not covered
--> $DIR/match-empty.rs:82:18
|
LL | / enum NonEmptyEnum2 {
LL | | Foo(bool),
LL | | Bar,
LL | | }
| |_- `NonEmptyEnum2` defined here
...
LL | match_false!(NonEmptyEnum2::Foo(true));
| ^^^^^^^^^^^^^^^^^^^^^^^^ pattern `_` not covered
|
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
error[E0004]: non-exhaustive patterns: `_` not covered
--> $DIR/match-empty.rs:84:18
|
LL | / enum NonEmptyEnum5 {
LL | | V1, V2, V3, V4, V5,
LL | | }
| |_- `NonEmptyEnum5` defined here
...
LL | match_false!(NonEmptyEnum5::V1);
| ^^^^^^^^^^^^^^^^^ pattern `_` not covered
|
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
error: aborting due to 15 previous errors
For more information about this error, try `rustc --explain E0004`.