Skip to content

Commit 4e376cc

Browse files
committed
Test empty types better
1 parent f967532 commit 4e376cc

11 files changed

+2606
-502
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
error: unreachable pattern
2+
--> $DIR/empty-match-check-notes.rs:17:9
3+
|
4+
LL | _ => {}
5+
| ^
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/empty-match-check-notes.rs:7:9
9+
|
10+
LL | #![deny(unreachable_patterns)]
11+
| ^^^^^^^^^^^^^^^^^^^^
12+
13+
error: unreachable pattern
14+
--> $DIR/empty-match-check-notes.rs:20:9
15+
|
16+
LL | _ if false => {}
17+
| ^
18+
19+
error: unreachable pattern
20+
--> $DIR/empty-match-check-notes.rs:27:9
21+
|
22+
LL | _ => {}
23+
| ^
24+
25+
error: unreachable pattern
26+
--> $DIR/empty-match-check-notes.rs:30:9
27+
|
28+
LL | _ if false => {}
29+
| ^
30+
31+
error[E0005]: refutable pattern in local binding
32+
--> $DIR/empty-match-check-notes.rs:35:9
33+
|
34+
LL | let None = x;
35+
| ^^^^ pattern `Some(_)` not covered
36+
|
37+
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
38+
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
39+
= note: pattern `Some(_)` is currently uninhabited, but this variant contains private fields which may become inhabited in the future
40+
= note: the matched value is of type `Option<SecretlyUninhabitedForeignStruct>`
41+
help: you might want to use `if let` to ignore the variant that isn't matched
42+
|
43+
LL | if let None = x { todo!() };
44+
| ++ +++++++++++
45+
46+
error[E0004]: non-exhaustive patterns: `_` not covered
47+
--> $DIR/empty-match-check-notes.rs:45:11
48+
|
49+
LL | match 0u8 {
50+
| ^^^ pattern `_` not covered
51+
|
52+
= note: the matched value is of type `u8`
53+
= note: match arms with guards don't count towards exhaustivity
54+
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
55+
|
56+
LL ~ _ if false => {},
57+
LL + _ => todo!()
58+
|
59+
60+
error: aborting due to 6 previous errors
61+
62+
Some errors have detailed explanations: E0004, E0005.
63+
For more information about an error, try `rustc --explain E0004`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
error: unreachable pattern
2+
--> $DIR/empty-match-check-notes.rs:17:9
3+
|
4+
LL | _ => {}
5+
| ^
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/empty-match-check-notes.rs:7:9
9+
|
10+
LL | #![deny(unreachable_patterns)]
11+
| ^^^^^^^^^^^^^^^^^^^^
12+
13+
error: unreachable pattern
14+
--> $DIR/empty-match-check-notes.rs:20:9
15+
|
16+
LL | _ if false => {}
17+
| ^
18+
19+
error: unreachable pattern
20+
--> $DIR/empty-match-check-notes.rs:27:9
21+
|
22+
LL | _ => {}
23+
| ^
24+
25+
error: unreachable pattern
26+
--> $DIR/empty-match-check-notes.rs:30:9
27+
|
28+
LL | _ if false => {}
29+
| ^
30+
31+
error[E0005]: refutable pattern in local binding
32+
--> $DIR/empty-match-check-notes.rs:35:9
33+
|
34+
LL | let None = x;
35+
| ^^^^ pattern `Some(_)` not covered
36+
|
37+
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
38+
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
39+
= note: the matched value is of type `Option<SecretlyUninhabitedForeignStruct>`
40+
help: you might want to use `if let` to ignore the variant that isn't matched
41+
|
42+
LL | if let None = x { todo!() };
43+
| ++ +++++++++++
44+
45+
error[E0004]: non-exhaustive patterns: `_` not covered
46+
--> $DIR/empty-match-check-notes.rs:45:11
47+
|
48+
LL | match 0u8 {
49+
| ^^^ pattern `_` not covered
50+
|
51+
= note: the matched value is of type `u8`
52+
= note: match arms with guards don't count towards exhaustivity
53+
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
54+
|
55+
LL ~ _ if false => {},
56+
LL + _ => todo!()
57+
|
58+
59+
error: aborting due to 6 previous errors
60+
61+
Some errors have detailed explanations: E0004, E0005.
62+
For more information about an error, try `rustc --explain E0004`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// aux-build:empty.rs
2+
// revisions: normal exhaustive_patterns
3+
//
4+
// This tests a match with no arms on various types, and checks NOTEs.
5+
#![feature(never_type)]
6+
#![cfg_attr(exhaustive_patterns, feature(exhaustive_patterns))]
7+
#![deny(unreachable_patterns)]
8+
//~^ NOTE the lint level is defined here
9+
10+
extern crate empty;
11+
12+
enum EmptyEnum {}
13+
14+
fn empty_enum(x: EmptyEnum) {
15+
match x {} // ok
16+
match x {
17+
_ => {} //~ ERROR unreachable pattern
18+
}
19+
match x {
20+
_ if false => {} //~ ERROR unreachable pattern
21+
}
22+
}
23+
24+
fn empty_foreign_enum(x: empty::EmptyForeignEnum) {
25+
match x {} // ok
26+
match x {
27+
_ => {} //~ ERROR unreachable pattern
28+
}
29+
match x {
30+
_ if false => {} //~ ERROR unreachable pattern
31+
}
32+
}
33+
34+
fn empty_foreign_enum_private(x: Option<empty::SecretlyUninhabitedForeignStruct>) {
35+
let None = x;
36+
//~^ ERROR refutable pattern in local binding
37+
//~| NOTE `let` bindings require an "irrefutable pattern"
38+
//~| NOTE for more information, visit
39+
//~| NOTE the matched value is of type
40+
//~| NOTE pattern `Some(_)` not covered
41+
//[exhaustive_patterns]~| NOTE currently uninhabited, but this variant contains private fields
42+
}
43+
44+
fn main() {
45+
match 0u8 {
46+
//~^ ERROR `_` not covered
47+
//~| NOTE the matched value is of type
48+
//~| NOTE match arms with guards don't count towards exhaustivity
49+
//~| NOTE pattern `_` not covered
50+
_ if false => {}
51+
}
52+
}

0 commit comments

Comments
 (0)