mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 17:24:06 +00:00
Add tests
This commit is contained in:
parent
a601302ff0
commit
257ed899c8
@ -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
|
||||
}
|
||||
|
@ -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`.
|
||||
|
@ -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() {
|
||||
|
@ -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`.
|
||||
|
Loading…
Reference in New Issue
Block a user