Skip to content

Commit 257ed89

Browse files
committed
Add tests
1 parent a601302 commit 257ed89

File tree

4 files changed

+88
-42
lines changed

4 files changed

+88
-42
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![feature(never_type)]
2+
#![feature(never_type_fallback)]
23
#![feature(exhaustive_patterns)]
34
#![deny(unreachable_patterns)]
45
enum Foo {}
@@ -42,7 +43,17 @@ macro_rules! match_false {
4243
}
4344

4445
fn foo(x: Foo) {
45-
match_empty!(x); // ok
46+
match x {} // ok
47+
match x {
48+
_ => {}, //~ ERROR unreachable pattern
49+
}
50+
match x {
51+
_ if false => {}, //~ ERROR unreachable pattern
52+
}
53+
}
54+
55+
fn never(x: !) {
56+
match x {} // ok
4657
match x {
4758
_ => {}, //~ ERROR unreachable pattern
4859
}

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

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

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

1919
error: unreachable pattern
20-
--> $DIR/match-empty-exhaustive_patterns.rs:57:9
20+
--> $DIR/match-empty-exhaustive_patterns.rs:58:9
21+
|
22+
LL | _ => {},
23+
| ^
24+
25+
error: unreachable pattern
26+
--> $DIR/match-empty-exhaustive_patterns.rs:61:9
27+
|
28+
LL | _ if false => {},
29+
| ^
30+
31+
error: unreachable pattern
32+
--> $DIR/match-empty-exhaustive_patterns.rs:68:9
2133
|
2234
LL | Some(_) => {}
2335
| ^^^^^^^
2436

2537
error: unreachable pattern
26-
--> $DIR/match-empty-exhaustive_patterns.rs:61:9
38+
--> $DIR/match-empty-exhaustive_patterns.rs:72:9
2739
|
2840
LL | Some(_) => {}
2941
| ^^^^^^^
3042

3143
error[E0004]: non-exhaustive patterns: type `u8` is non-empty
32-
--> $DIR/match-empty-exhaustive_patterns.rs:64:18
44+
--> $DIR/match-empty-exhaustive_patterns.rs:75:18
3345
|
3446
LL | match_empty!(0u8);
3547
| ^^^
@@ -38,7 +50,7 @@ LL | match_empty!(0u8);
3850
= note: the matched value is of type `u8`
3951

4052
error[E0004]: non-exhaustive patterns: type `NonEmptyStruct` is non-empty
41-
--> $DIR/match-empty-exhaustive_patterns.rs:66:18
53+
--> $DIR/match-empty-exhaustive_patterns.rs:77:18
4254
|
4355
LL | struct NonEmptyStruct(bool);
4456
| ---------------------------- `NonEmptyStruct` defined here
@@ -50,7 +62,7 @@ LL | match_empty!(NonEmptyStruct(true));
5062
= note: the matched value is of type `NonEmptyStruct`
5163

5264
error[E0004]: non-exhaustive patterns: type `NonEmptyUnion1` is non-empty
53-
--> $DIR/match-empty-exhaustive_patterns.rs:68:18
65+
--> $DIR/match-empty-exhaustive_patterns.rs:79:18
5466
|
5567
LL | / union NonEmptyUnion1 {
5668
LL | | foo: (),
@@ -64,7 +76,7 @@ LL | match_empty!((NonEmptyUnion1 { foo: () }));
6476
= note: the matched value is of type `NonEmptyUnion1`
6577

6678
error[E0004]: non-exhaustive patterns: type `NonEmptyUnion2` is non-empty
67-
--> $DIR/match-empty-exhaustive_patterns.rs:70:18
79+
--> $DIR/match-empty-exhaustive_patterns.rs:81:18
6880
|
6981
LL | / union NonEmptyUnion2 {
7082
LL | | foo: (),
@@ -79,7 +91,7 @@ LL | match_empty!((NonEmptyUnion2 { foo: () }));
7991
= note: the matched value is of type `NonEmptyUnion2`
8092

8193
error[E0004]: non-exhaustive patterns: `Foo(_)` not covered
82-
--> $DIR/match-empty-exhaustive_patterns.rs:72:18
94+
--> $DIR/match-empty-exhaustive_patterns.rs:83:18
8395
|
8496
LL | / enum NonEmptyEnum1 {
8597
LL | | Foo(bool),
@@ -96,7 +108,7 @@ LL | match_empty!(NonEmptyEnum1::Foo(true));
96108
= note: the matched value is of type `NonEmptyEnum1`
97109

98110
error[E0004]: non-exhaustive patterns: `Foo(_)` and `Bar` not covered
99-
--> $DIR/match-empty-exhaustive_patterns.rs:74:18
111+
--> $DIR/match-empty-exhaustive_patterns.rs:85:18
100112
|
101113
LL | / enum NonEmptyEnum2 {
102114
LL | | Foo(bool),
@@ -117,7 +129,7 @@ LL | match_empty!(NonEmptyEnum2::Foo(true));
117129
= note: the matched value is of type `NonEmptyEnum2`
118130

119131
error[E0004]: non-exhaustive patterns: `V1`, `V2`, `V3` and 2 more not covered
120-
--> $DIR/match-empty-exhaustive_patterns.rs:76:18
132+
--> $DIR/match-empty-exhaustive_patterns.rs:87:18
121133
|
122134
LL | / enum NonEmptyEnum5 {
123135
LL | | V1, V2, V3, V4, V5,
@@ -131,7 +143,7 @@ LL | match_empty!(NonEmptyEnum5::V1);
131143
= note: the matched value is of type `NonEmptyEnum5`
132144

133145
error[E0004]: non-exhaustive patterns: `_` not covered
134-
--> $DIR/match-empty-exhaustive_patterns.rs:79:18
146+
--> $DIR/match-empty-exhaustive_patterns.rs:90:18
135147
|
136148
LL | match_false!(0u8);
137149
| ^^^ pattern `_` not covered
@@ -140,7 +152,7 @@ LL | match_false!(0u8);
140152
= note: the matched value is of type `u8`
141153

142154
error[E0004]: non-exhaustive patterns: `NonEmptyStruct(_)` not covered
143-
--> $DIR/match-empty-exhaustive_patterns.rs:81:18
155+
--> $DIR/match-empty-exhaustive_patterns.rs:92:18
144156
|
145157
LL | struct NonEmptyStruct(bool);
146158
| ---------------------------- `NonEmptyStruct` defined here
@@ -152,7 +164,7 @@ LL | match_false!(NonEmptyStruct(true));
152164
= note: the matched value is of type `NonEmptyStruct`
153165

154166
error[E0004]: non-exhaustive patterns: `NonEmptyUnion1 { .. }` not covered
155-
--> $DIR/match-empty-exhaustive_patterns.rs:83:18
167+
--> $DIR/match-empty-exhaustive_patterns.rs:94:18
156168
|
157169
LL | / union NonEmptyUnion1 {
158170
LL | | foo: (),
@@ -166,7 +178,7 @@ LL | match_false!((NonEmptyUnion1 { foo: () }));
166178
= note: the matched value is of type `NonEmptyUnion1`
167179

168180
error[E0004]: non-exhaustive patterns: `NonEmptyUnion2 { .. }` not covered
169-
--> $DIR/match-empty-exhaustive_patterns.rs:85:18
181+
--> $DIR/match-empty-exhaustive_patterns.rs:96:18
170182
|
171183
LL | / union NonEmptyUnion2 {
172184
LL | | foo: (),
@@ -181,7 +193,7 @@ LL | match_false!((NonEmptyUnion2 { foo: () }));
181193
= note: the matched value is of type `NonEmptyUnion2`
182194

183195
error[E0004]: non-exhaustive patterns: `Foo(_)` not covered
184-
--> $DIR/match-empty-exhaustive_patterns.rs:87:18
196+
--> $DIR/match-empty-exhaustive_patterns.rs:98:18
185197
|
186198
LL | / enum NonEmptyEnum1 {
187199
LL | | Foo(bool),
@@ -198,7 +210,7 @@ LL | match_false!(NonEmptyEnum1::Foo(true));
198210
= note: the matched value is of type `NonEmptyEnum1`
199211

200212
error[E0004]: non-exhaustive patterns: `Foo(_)` and `Bar` not covered
201-
--> $DIR/match-empty-exhaustive_patterns.rs:89:18
213+
--> $DIR/match-empty-exhaustive_patterns.rs:100:18
202214
|
203215
LL | / enum NonEmptyEnum2 {
204216
LL | | Foo(bool),
@@ -219,7 +231,7 @@ LL | match_false!(NonEmptyEnum2::Foo(true));
219231
= note: the matched value is of type `NonEmptyEnum2`
220232

221233
error[E0004]: non-exhaustive patterns: `V1`, `V2`, `V3` and 2 more not covered
222-
--> $DIR/match-empty-exhaustive_patterns.rs:91:18
234+
--> $DIR/match-empty-exhaustive_patterns.rs:102:18
223235
|
224236
LL | / enum NonEmptyEnum5 {
225237
LL | | V1, V2, V3, V4, V5,
@@ -232,6 +244,6 @@ LL | match_false!(NonEmptyEnum5::V1);
232244
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
233245
= note: the matched value is of type `NonEmptyEnum5`
234246

235-
error: aborting due to 18 previous errors
247+
error: aborting due to 20 previous errors
236248

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

src/test/ui/pattern/usefulness/match-empty.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![feature(never_type)]
2+
#![feature(never_type_fallback)]
23
#![deny(unreachable_patterns)]
34
enum Foo {}
45

@@ -41,12 +42,25 @@ macro_rules! match_false {
4142
}
4243

4344
fn foo(x: Foo) {
44-
match_empty!(x); // ok
45-
match_false!(x); // Not detected as unreachable nor exhaustive.
46-
//~^ ERROR non-exhaustive patterns: `_` not covered
45+
match x {} // ok
4746
match x {
4847
_ => {}, // Not detected as unreachable, see #55123.
4948
}
49+
match x {
50+
//~^ ERROR non-exhaustive patterns: `_` not covered
51+
_ if false => {}, // Not detected as unreachable nor exhaustive.
52+
}
53+
}
54+
55+
fn never(x: !) {
56+
match x {} // ok
57+
match x {
58+
_ => {}, // Not detected as unreachable.
59+
}
60+
match x {
61+
//~^ ERROR non-exhaustive patterns: `_` not covered
62+
_ if false => {}, // Not detected as unreachable nor exhaustive.
63+
}
5064
}
5165

5266
fn main() {

src/test/ui/pattern/usefulness/match-empty.stderr

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
error[E0004]: non-exhaustive patterns: `_` not covered
2-
--> $DIR/match-empty.rs:45:18
2+
--> $DIR/match-empty.rs:49:11
33
|
44
LL | enum Foo {}
55
| ----------- `Foo` defined here
66
...
7-
LL | match_false!(x); // Not detected as unreachable nor exhaustive.
8-
| ^ pattern `_` not covered
7+
LL | match x {
8+
| ^ pattern `_` not covered
99
|
1010
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
1111
= note: the matched value is of type `Foo`
1212

13+
error[E0004]: non-exhaustive patterns: `_` not covered
14+
--> $DIR/match-empty.rs:60:11
15+
|
16+
LL | match x {
17+
| ^ pattern `_` not covered
18+
|
19+
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
20+
= note: the matched value is of type `!`
21+
1322
error[E0004]: non-exhaustive patterns: type `u8` is non-empty
14-
--> $DIR/match-empty.rs:63:18
23+
--> $DIR/match-empty.rs:77:18
1524
|
1625
LL | match_empty!(0u8);
1726
| ^^^
@@ -20,7 +29,7 @@ LL | match_empty!(0u8);
2029
= note: the matched value is of type `u8`
2130

2231
error[E0004]: non-exhaustive patterns: type `NonEmptyStruct` is non-empty
23-
--> $DIR/match-empty.rs:65:18
32+
--> $DIR/match-empty.rs:79:18
2433
|
2534
LL | struct NonEmptyStruct(bool);
2635
| ---------------------------- `NonEmptyStruct` defined here
@@ -32,7 +41,7 @@ LL | match_empty!(NonEmptyStruct(true));
3241
= note: the matched value is of type `NonEmptyStruct`
3342

3443
error[E0004]: non-exhaustive patterns: type `NonEmptyUnion1` is non-empty
35-
--> $DIR/match-empty.rs:67:18
44+
--> $DIR/match-empty.rs:81:18
3645
|
3746
LL | / union NonEmptyUnion1 {
3847
LL | | foo: (),
@@ -46,7 +55,7 @@ LL | match_empty!((NonEmptyUnion1 { foo: () }));
4655
= note: the matched value is of type `NonEmptyUnion1`
4756

4857
error[E0004]: non-exhaustive patterns: type `NonEmptyUnion2` is non-empty
49-
--> $DIR/match-empty.rs:69:18
58+
--> $DIR/match-empty.rs:83:18
5059
|
5160
LL | / union NonEmptyUnion2 {
5261
LL | | foo: (),
@@ -61,7 +70,7 @@ LL | match_empty!((NonEmptyUnion2 { foo: () }));
6170
= note: the matched value is of type `NonEmptyUnion2`
6271

6372
error[E0004]: non-exhaustive patterns: `Foo(_)` not covered
64-
--> $DIR/match-empty.rs:71:18
73+
--> $DIR/match-empty.rs:85:18
6574
|
6675
LL | / enum NonEmptyEnum1 {
6776
LL | | Foo(bool),
@@ -78,7 +87,7 @@ LL | match_empty!(NonEmptyEnum1::Foo(true));
7887
= note: the matched value is of type `NonEmptyEnum1`
7988

8089
error[E0004]: non-exhaustive patterns: `Foo(_)` and `Bar` not covered
81-
--> $DIR/match-empty.rs:73:18
90+
--> $DIR/match-empty.rs:87:18
8291
|
8392
LL | / enum NonEmptyEnum2 {
8493
LL | | Foo(bool),
@@ -99,7 +108,7 @@ LL | match_empty!(NonEmptyEnum2::Foo(true));
99108
= note: the matched value is of type `NonEmptyEnum2`
100109

101110
error[E0004]: non-exhaustive patterns: `V1`, `V2`, `V3` and 2 more not covered
102-
--> $DIR/match-empty.rs:75:18
111+
--> $DIR/match-empty.rs:89:18
103112
|
104113
LL | / enum NonEmptyEnum5 {
105114
LL | | V1, V2, V3, V4, V5,
@@ -113,7 +122,7 @@ LL | match_empty!(NonEmptyEnum5::V1);
113122
= note: the matched value is of type `NonEmptyEnum5`
114123

115124
error[E0004]: non-exhaustive patterns: `_` not covered
116-
--> $DIR/match-empty.rs:78:18
125+
--> $DIR/match-empty.rs:92:18
117126
|
118127
LL | match_false!(0u8);
119128
| ^^^ pattern `_` not covered
@@ -122,7 +131,7 @@ LL | match_false!(0u8);
122131
= note: the matched value is of type `u8`
123132

124133
error[E0004]: non-exhaustive patterns: `NonEmptyStruct(_)` not covered
125-
--> $DIR/match-empty.rs:80:18
134+
--> $DIR/match-empty.rs:94:18
126135
|
127136
LL | struct NonEmptyStruct(bool);
128137
| ---------------------------- `NonEmptyStruct` defined here
@@ -134,7 +143,7 @@ LL | match_false!(NonEmptyStruct(true));
134143
= note: the matched value is of type `NonEmptyStruct`
135144

136145
error[E0004]: non-exhaustive patterns: `NonEmptyUnion1 { .. }` not covered
137-
--> $DIR/match-empty.rs:82:18
146+
--> $DIR/match-empty.rs:96:18
138147
|
139148
LL | / union NonEmptyUnion1 {
140149
LL | | foo: (),
@@ -148,7 +157,7 @@ LL | match_false!((NonEmptyUnion1 { foo: () }));
148157
= note: the matched value is of type `NonEmptyUnion1`
149158

150159
error[E0004]: non-exhaustive patterns: `NonEmptyUnion2 { .. }` not covered
151-
--> $DIR/match-empty.rs:84:18
160+
--> $DIR/match-empty.rs:98:18
152161
|
153162
LL | / union NonEmptyUnion2 {
154163
LL | | foo: (),
@@ -163,7 +172,7 @@ LL | match_false!((NonEmptyUnion2 { foo: () }));
163172
= note: the matched value is of type `NonEmptyUnion2`
164173

165174
error[E0004]: non-exhaustive patterns: `Foo(_)` not covered
166-
--> $DIR/match-empty.rs:86:18
175+
--> $DIR/match-empty.rs:100:18
167176
|
168177
LL | / enum NonEmptyEnum1 {
169178
LL | | Foo(bool),
@@ -180,7 +189,7 @@ LL | match_false!(NonEmptyEnum1::Foo(true));
180189
= note: the matched value is of type `NonEmptyEnum1`
181190

182191
error[E0004]: non-exhaustive patterns: `Foo(_)` and `Bar` not covered
183-
--> $DIR/match-empty.rs:88:18
192+
--> $DIR/match-empty.rs:102:18
184193
|
185194
LL | / enum NonEmptyEnum2 {
186195
LL | | Foo(bool),
@@ -201,7 +210,7 @@ LL | match_false!(NonEmptyEnum2::Foo(true));
201210
= note: the matched value is of type `NonEmptyEnum2`
202211

203212
error[E0004]: non-exhaustive patterns: `V1`, `V2`, `V3` and 2 more not covered
204-
--> $DIR/match-empty.rs:90:18
213+
--> $DIR/match-empty.rs:104:18
205214
|
206215
LL | / enum NonEmptyEnum5 {
207216
LL | | V1, V2, V3, V4, V5,
@@ -214,6 +223,6 @@ LL | match_false!(NonEmptyEnum5::V1);
214223
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
215224
= note: the matched value is of type `NonEmptyEnum5`
216225

217-
error: aborting due to 15 previous errors
226+
error: aborting due to 16 previous errors
218227

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

0 commit comments

Comments
 (0)