Skip to content

Commit 69821cf

Browse files
committed
Add a test for foreign empty enums
1 parent 36e3409 commit 69821cf

File tree

5 files changed

+102
-48
lines changed

5 files changed

+102
-48
lines changed

Diff for: src/test/ui/pattern/usefulness/auxiliary/empty.rs

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#![crate_type = "rlib"]
2+
pub enum EmptyForeignEnum {}

Diff for: src/test/ui/pattern/usefulness/match-empty-exhaustive_patterns.rs

+17-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
// aux-build:empty.rs
12
#![feature(never_type)]
23
#![feature(never_type_fallback)]
34
#![feature(exhaustive_patterns)]
45
#![deny(unreachable_patterns)]
5-
enum Foo {}
6+
7+
extern crate empty;
8+
9+
enum EmptyEnum {}
610

711
struct NonEmptyStruct(bool); //~ `NonEmptyStruct` defined here
812
union NonEmptyUnion1 { //~ `NonEmptyUnion1` defined here
@@ -42,7 +46,17 @@ macro_rules! match_false {
4246
};
4347
}
4448

45-
fn foo(x: Foo) {
49+
fn empty_enum(x: EmptyEnum) {
50+
match x {} // ok
51+
match x {
52+
_ => {}, //~ ERROR unreachable pattern
53+
}
54+
match x {
55+
_ if false => {}, //~ ERROR unreachable pattern
56+
}
57+
}
58+
59+
fn empty_foreign_enum(x: empty::EmptyForeignEnum) {
4660
match x {} // ok
4761
match x {
4862
_ => {}, //~ ERROR unreachable pattern
@@ -67,7 +81,7 @@ fn main() {
6781
None => {}
6882
Some(_) => {} //~ ERROR unreachable pattern
6983
}
70-
match None::<Foo> {
84+
match None::<EmptyEnum> {
7185
None => {}
7286
Some(_) => {} //~ ERROR unreachable pattern
7387
}

Diff for: src/test/ui/pattern/usefulness/match-empty-exhaustive_patterns.stderr

+34-22
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,59 @@
11
error: unreachable pattern
2-
--> $DIR/match-empty-exhaustive_patterns.rs:48:9
2+
--> $DIR/match-empty-exhaustive_patterns.rs:52:9
33
|
44
LL | _ => {},
55
| ^
66
|
77
note: the lint level is defined here
8-
--> $DIR/match-empty-exhaustive_patterns.rs:4:9
8+
--> $DIR/match-empty-exhaustive_patterns.rs:5:9
99
|
1010
LL | #![deny(unreachable_patterns)]
1111
| ^^^^^^^^^^^^^^^^^^^^
1212

1313
error: unreachable pattern
14-
--> $DIR/match-empty-exhaustive_patterns.rs:51:9
14+
--> $DIR/match-empty-exhaustive_patterns.rs:55:9
1515
|
1616
LL | _ if false => {},
1717
| ^
1818

1919
error: unreachable pattern
20-
--> $DIR/match-empty-exhaustive_patterns.rs:58:9
20+
--> $DIR/match-empty-exhaustive_patterns.rs:62:9
2121
|
2222
LL | _ => {},
2323
| ^
2424

2525
error: unreachable pattern
26-
--> $DIR/match-empty-exhaustive_patterns.rs:61:9
26+
--> $DIR/match-empty-exhaustive_patterns.rs:65:9
2727
|
2828
LL | _ if false => {},
2929
| ^
3030

3131
error: unreachable pattern
32-
--> $DIR/match-empty-exhaustive_patterns.rs:68:9
32+
--> $DIR/match-empty-exhaustive_patterns.rs:72:9
33+
|
34+
LL | _ => {},
35+
| ^
36+
37+
error: unreachable pattern
38+
--> $DIR/match-empty-exhaustive_patterns.rs:75:9
39+
|
40+
LL | _ if false => {},
41+
| ^
42+
43+
error: unreachable pattern
44+
--> $DIR/match-empty-exhaustive_patterns.rs:82:9
3345
|
3446
LL | Some(_) => {}
3547
| ^^^^^^^
3648

3749
error: unreachable pattern
38-
--> $DIR/match-empty-exhaustive_patterns.rs:72:9
50+
--> $DIR/match-empty-exhaustive_patterns.rs:86:9
3951
|
4052
LL | Some(_) => {}
4153
| ^^^^^^^
4254

4355
error[E0004]: non-exhaustive patterns: type `u8` is non-empty
44-
--> $DIR/match-empty-exhaustive_patterns.rs:75:18
56+
--> $DIR/match-empty-exhaustive_patterns.rs:89:18
4557
|
4658
LL | match_empty!(0u8);
4759
| ^^^
@@ -50,7 +62,7 @@ LL | match_empty!(0u8);
5062
= note: the matched value is of type `u8`
5163

5264
error[E0004]: non-exhaustive patterns: type `NonEmptyStruct` is non-empty
53-
--> $DIR/match-empty-exhaustive_patterns.rs:77:18
65+
--> $DIR/match-empty-exhaustive_patterns.rs:91:18
5466
|
5567
LL | struct NonEmptyStruct(bool);
5668
| ---------------------------- `NonEmptyStruct` defined here
@@ -62,7 +74,7 @@ LL | match_empty!(NonEmptyStruct(true));
6274
= note: the matched value is of type `NonEmptyStruct`
6375

6476
error[E0004]: non-exhaustive patterns: type `NonEmptyUnion1` is non-empty
65-
--> $DIR/match-empty-exhaustive_patterns.rs:79:18
77+
--> $DIR/match-empty-exhaustive_patterns.rs:93:18
6678
|
6779
LL | / union NonEmptyUnion1 {
6880
LL | | foo: (),
@@ -76,7 +88,7 @@ LL | match_empty!((NonEmptyUnion1 { foo: () }));
7688
= note: the matched value is of type `NonEmptyUnion1`
7789

7890
error[E0004]: non-exhaustive patterns: type `NonEmptyUnion2` is non-empty
79-
--> $DIR/match-empty-exhaustive_patterns.rs:81:18
91+
--> $DIR/match-empty-exhaustive_patterns.rs:95:18
8092
|
8193
LL | / union NonEmptyUnion2 {
8294
LL | | foo: (),
@@ -91,7 +103,7 @@ LL | match_empty!((NonEmptyUnion2 { foo: () }));
91103
= note: the matched value is of type `NonEmptyUnion2`
92104

93105
error[E0004]: non-exhaustive patterns: `Foo(_)` not covered
94-
--> $DIR/match-empty-exhaustive_patterns.rs:83:18
106+
--> $DIR/match-empty-exhaustive_patterns.rs:97:18
95107
|
96108
LL | / enum NonEmptyEnum1 {
97109
LL | | Foo(bool),
@@ -108,7 +120,7 @@ LL | match_empty!(NonEmptyEnum1::Foo(true));
108120
= note: the matched value is of type `NonEmptyEnum1`
109121

110122
error[E0004]: non-exhaustive patterns: `Foo(_)` and `Bar` not covered
111-
--> $DIR/match-empty-exhaustive_patterns.rs:85:18
123+
--> $DIR/match-empty-exhaustive_patterns.rs:99:18
112124
|
113125
LL | / enum NonEmptyEnum2 {
114126
LL | | Foo(bool),
@@ -129,7 +141,7 @@ LL | match_empty!(NonEmptyEnum2::Foo(true));
129141
= note: the matched value is of type `NonEmptyEnum2`
130142

131143
error[E0004]: non-exhaustive patterns: `V1`, `V2`, `V3` and 2 more not covered
132-
--> $DIR/match-empty-exhaustive_patterns.rs:87:18
144+
--> $DIR/match-empty-exhaustive_patterns.rs:101:18
133145
|
134146
LL | / enum NonEmptyEnum5 {
135147
LL | | V1, V2, V3, V4, V5,
@@ -143,7 +155,7 @@ LL | match_empty!(NonEmptyEnum5::V1);
143155
= note: the matched value is of type `NonEmptyEnum5`
144156

145157
error[E0004]: non-exhaustive patterns: `_` not covered
146-
--> $DIR/match-empty-exhaustive_patterns.rs:90:18
158+
--> $DIR/match-empty-exhaustive_patterns.rs:104:18
147159
|
148160
LL | match_false!(0u8);
149161
| ^^^ pattern `_` not covered
@@ -152,7 +164,7 @@ LL | match_false!(0u8);
152164
= note: the matched value is of type `u8`
153165

154166
error[E0004]: non-exhaustive patterns: `NonEmptyStruct(_)` not covered
155-
--> $DIR/match-empty-exhaustive_patterns.rs:92:18
167+
--> $DIR/match-empty-exhaustive_patterns.rs:106:18
156168
|
157169
LL | struct NonEmptyStruct(bool);
158170
| ---------------------------- `NonEmptyStruct` defined here
@@ -164,7 +176,7 @@ LL | match_false!(NonEmptyStruct(true));
164176
= note: the matched value is of type `NonEmptyStruct`
165177

166178
error[E0004]: non-exhaustive patterns: `NonEmptyUnion1 { .. }` not covered
167-
--> $DIR/match-empty-exhaustive_patterns.rs:94:18
179+
--> $DIR/match-empty-exhaustive_patterns.rs:108:18
168180
|
169181
LL | / union NonEmptyUnion1 {
170182
LL | | foo: (),
@@ -178,7 +190,7 @@ LL | match_false!((NonEmptyUnion1 { foo: () }));
178190
= note: the matched value is of type `NonEmptyUnion1`
179191

180192
error[E0004]: non-exhaustive patterns: `NonEmptyUnion2 { .. }` not covered
181-
--> $DIR/match-empty-exhaustive_patterns.rs:96:18
193+
--> $DIR/match-empty-exhaustive_patterns.rs:110:18
182194
|
183195
LL | / union NonEmptyUnion2 {
184196
LL | | foo: (),
@@ -193,7 +205,7 @@ LL | match_false!((NonEmptyUnion2 { foo: () }));
193205
= note: the matched value is of type `NonEmptyUnion2`
194206

195207
error[E0004]: non-exhaustive patterns: `Foo(_)` not covered
196-
--> $DIR/match-empty-exhaustive_patterns.rs:98:18
208+
--> $DIR/match-empty-exhaustive_patterns.rs:112:18
197209
|
198210
LL | / enum NonEmptyEnum1 {
199211
LL | | Foo(bool),
@@ -210,7 +222,7 @@ LL | match_false!(NonEmptyEnum1::Foo(true));
210222
= note: the matched value is of type `NonEmptyEnum1`
211223

212224
error[E0004]: non-exhaustive patterns: `Foo(_)` and `Bar` not covered
213-
--> $DIR/match-empty-exhaustive_patterns.rs:100:18
225+
--> $DIR/match-empty-exhaustive_patterns.rs:114:18
214226
|
215227
LL | / enum NonEmptyEnum2 {
216228
LL | | Foo(bool),
@@ -231,7 +243,7 @@ LL | match_false!(NonEmptyEnum2::Foo(true));
231243
= note: the matched value is of type `NonEmptyEnum2`
232244

233245
error[E0004]: non-exhaustive patterns: `V1`, `V2`, `V3` and 2 more not covered
234-
--> $DIR/match-empty-exhaustive_patterns.rs:102:18
246+
--> $DIR/match-empty-exhaustive_patterns.rs:116:18
235247
|
236248
LL | / enum NonEmptyEnum5 {
237249
LL | | V1, V2, V3, V4, V5,
@@ -244,6 +256,6 @@ LL | match_false!(NonEmptyEnum5::V1);
244256
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
245257
= note: the matched value is of type `NonEmptyEnum5`
246258

247-
error: aborting due to 20 previous errors
259+
error: aborting due to 22 previous errors
248260

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

Diff for: src/test/ui/pattern/usefulness/match-empty.rs

+17-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
// aux-build:empty.rs
12
#![feature(never_type)]
23
#![feature(never_type_fallback)]
34
#![deny(unreachable_patterns)]
4-
enum Foo {}
5+
6+
extern crate empty;
7+
8+
enum EmptyEnum {}
59

610
struct NonEmptyStruct(bool); //~ `NonEmptyStruct` defined here
711
union NonEmptyUnion1 { //~ `NonEmptyUnion1` defined here
@@ -41,7 +45,17 @@ macro_rules! match_false {
4145
};
4246
}
4347

44-
fn foo(x: Foo) {
48+
fn empty_enum(x: EmptyEnum) {
49+
match x {} // ok
50+
match x {
51+
_ => {}, //~ ERROR unreachable pattern
52+
}
53+
match x {
54+
_ if false => {}, //~ ERROR unreachable pattern
55+
}
56+
}
57+
58+
fn empty_foreign_enum(x: empty::EmptyForeignEnum) {
4559
match x {} // ok
4660
match x {
4761
_ => {}, //~ ERROR unreachable pattern
@@ -67,7 +81,7 @@ fn main() {
6781
None => {}
6882
Some(_) => {}
6983
}
70-
match None::<Foo> {
84+
match None::<EmptyEnum> {
7185
None => {}
7286
Some(_) => {}
7387
}

0 commit comments

Comments
 (0)