Skip to content

Commit a1d0cdb

Browse files
committed
Test that 0/unknown-length arrays are nonempty
1 parent d0601da commit a1d0cdb

File tree

3 files changed

+144
-47
lines changed

3 files changed

+144
-47
lines changed

tests/ui/pattern/usefulness/empty-match.exhaustive_patterns.stderr

+69-23
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0004]: non-exhaustive patterns: type `u8` is non-empty
2-
--> $DIR/empty-match.rs:46:20
2+
--> $DIR/empty-match.rs:47:20
33
|
44
LL | match_no_arms!(0u8);
55
| ^^^
@@ -8,7 +8,7 @@ LL | match_no_arms!(0u8);
88
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern
99

1010
error[E0004]: non-exhaustive patterns: type `i8` is non-empty
11-
--> $DIR/empty-match.rs:47:20
11+
--> $DIR/empty-match.rs:48:20
1212
|
1313
LL | match_no_arms!(0i8);
1414
| ^^^
@@ -17,7 +17,7 @@ LL | match_no_arms!(0i8);
1717
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern
1818

1919
error[E0004]: non-exhaustive patterns: type `usize` is non-empty
20-
--> $DIR/empty-match.rs:48:20
20+
--> $DIR/empty-match.rs:49:20
2121
|
2222
LL | match_no_arms!(0usize);
2323
| ^^^^^^
@@ -26,7 +26,7 @@ LL | match_no_arms!(0usize);
2626
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern
2727

2828
error[E0004]: non-exhaustive patterns: type `isize` is non-empty
29-
--> $DIR/empty-match.rs:49:20
29+
--> $DIR/empty-match.rs:50:20
3030
|
3131
LL | match_no_arms!(0isize);
3232
| ^^^^^^
@@ -35,7 +35,7 @@ LL | match_no_arms!(0isize);
3535
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern
3636

3737
error[E0004]: non-exhaustive patterns: type `NonEmptyStruct1` is non-empty
38-
--> $DIR/empty-match.rs:50:20
38+
--> $DIR/empty-match.rs:51:20
3939
|
4040
LL | match_no_arms!(NonEmptyStruct1);
4141
| ^^^^^^^^^^^^^^^
@@ -49,7 +49,7 @@ LL | struct NonEmptyStruct1;
4949
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern
5050

5151
error[E0004]: non-exhaustive patterns: type `NonEmptyStruct2` is non-empty
52-
--> $DIR/empty-match.rs:51:20
52+
--> $DIR/empty-match.rs:52:20
5353
|
5454
LL | match_no_arms!(NonEmptyStruct2(true));
5555
| ^^^^^^^^^^^^^^^^^^^^^
@@ -63,7 +63,7 @@ LL | struct NonEmptyStruct2(bool);
6363
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern
6464

6565
error[E0004]: non-exhaustive patterns: type `NonEmptyUnion1` is non-empty
66-
--> $DIR/empty-match.rs:52:20
66+
--> $DIR/empty-match.rs:53:20
6767
|
6868
LL | match_no_arms!((NonEmptyUnion1 { foo: () }));
6969
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -77,7 +77,7 @@ LL | union NonEmptyUnion1 {
7777
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern
7878

7979
error[E0004]: non-exhaustive patterns: type `NonEmptyUnion2` is non-empty
80-
--> $DIR/empty-match.rs:53:20
80+
--> $DIR/empty-match.rs:54:20
8181
|
8282
LL | match_no_arms!((NonEmptyUnion2 { foo: () }));
8383
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -91,7 +91,7 @@ LL | union NonEmptyUnion2 {
9191
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern
9292

9393
error[E0004]: non-exhaustive patterns: `NonEmptyEnum1::Foo(_)` not covered
94-
--> $DIR/empty-match.rs:54:20
94+
--> $DIR/empty-match.rs:55:20
9595
|
9696
LL | match_no_arms!(NonEmptyEnum1::Foo(true));
9797
| ^^^^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyEnum1::Foo(_)` not covered
@@ -107,7 +107,7 @@ LL | Foo(bool),
107107
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern
108108

109109
error[E0004]: non-exhaustive patterns: `NonEmptyEnum2::Foo(_)` and `NonEmptyEnum2::Bar` not covered
110-
--> $DIR/empty-match.rs:55:20
110+
--> $DIR/empty-match.rs:56:20
111111
|
112112
LL | match_no_arms!(NonEmptyEnum2::Foo(true));
113113
| ^^^^^^^^^^^^^^^^^^^^^^^^ patterns `NonEmptyEnum2::Foo(_)` and `NonEmptyEnum2::Bar` not covered
@@ -125,7 +125,7 @@ LL | Bar,
125125
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or multiple match arms
126126

127127
error[E0004]: non-exhaustive patterns: `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered
128-
--> $DIR/empty-match.rs:56:20
128+
--> $DIR/empty-match.rs:57:20
129129
|
130130
LL | match_no_arms!(NonEmptyEnum5::V1);
131131
| ^^^^^^^^^^^^^^^^^ patterns `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered
@@ -148,8 +148,26 @@ LL | V5,
148148
= note: the matched value is of type `NonEmptyEnum5`
149149
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or multiple match arms
150150

151+
error[E0004]: non-exhaustive patterns: type `[!; 0]` is non-empty
152+
--> $DIR/empty-match.rs:58:20
153+
|
154+
LL | match_no_arms!(array0_of_empty);
155+
| ^^^^^^^^^^^^^^^
156+
|
157+
= note: the matched value is of type `[!; 0]`
158+
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern
159+
160+
error[E0004]: non-exhaustive patterns: type `[!; N]` is non-empty
161+
--> $DIR/empty-match.rs:59:20
162+
|
163+
LL | match_no_arms!(arrayN_of_empty);
164+
| ^^^^^^^^^^^^^^^
165+
|
166+
= note: the matched value is of type `[!; N]`
167+
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern
168+
151169
error[E0004]: non-exhaustive patterns: `0_u8..=u8::MAX` not covered
152-
--> $DIR/empty-match.rs:58:24
170+
--> $DIR/empty-match.rs:61:24
153171
|
154172
LL | match_guarded_arm!(0u8);
155173
| ^^^ pattern `0_u8..=u8::MAX` not covered
@@ -163,7 +181,7 @@ LL + 0_u8..=u8::MAX => todo!()
163181
|
164182

165183
error[E0004]: non-exhaustive patterns: `i8::MIN..=i8::MAX` not covered
166-
--> $DIR/empty-match.rs:59:24
184+
--> $DIR/empty-match.rs:62:24
167185
|
168186
LL | match_guarded_arm!(0i8);
169187
| ^^^ pattern `i8::MIN..=i8::MAX` not covered
@@ -177,7 +195,7 @@ LL + i8::MIN..=i8::MAX => todo!()
177195
|
178196

179197
error[E0004]: non-exhaustive patterns: `0_usize..` not covered
180-
--> $DIR/empty-match.rs:60:24
198+
--> $DIR/empty-match.rs:63:24
181199
|
182200
LL | match_guarded_arm!(0usize);
183201
| ^^^^^^ pattern `0_usize..` not covered
@@ -191,7 +209,7 @@ LL + 0_usize.. => todo!()
191209
|
192210

193211
error[E0004]: non-exhaustive patterns: `_` not covered
194-
--> $DIR/empty-match.rs:61:24
212+
--> $DIR/empty-match.rs:64:24
195213
|
196214
LL | match_guarded_arm!(0isize);
197215
| ^^^^^^ pattern `_` not covered
@@ -205,7 +223,7 @@ LL + _ => todo!()
205223
|
206224

207225
error[E0004]: non-exhaustive patterns: `NonEmptyStruct1` not covered
208-
--> $DIR/empty-match.rs:62:24
226+
--> $DIR/empty-match.rs:65:24
209227
|
210228
LL | match_guarded_arm!(NonEmptyStruct1);
211229
| ^^^^^^^^^^^^^^^ pattern `NonEmptyStruct1` not covered
@@ -224,7 +242,7 @@ LL + NonEmptyStruct1 => todo!()
224242
|
225243

226244
error[E0004]: non-exhaustive patterns: `NonEmptyStruct2(_)` not covered
227-
--> $DIR/empty-match.rs:63:24
245+
--> $DIR/empty-match.rs:66:24
228246
|
229247
LL | match_guarded_arm!(NonEmptyStruct2(true));
230248
| ^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyStruct2(_)` not covered
@@ -243,7 +261,7 @@ LL + NonEmptyStruct2(_) => todo!()
243261
|
244262

245263
error[E0004]: non-exhaustive patterns: `NonEmptyUnion1 { .. }` not covered
246-
--> $DIR/empty-match.rs:64:24
264+
--> $DIR/empty-match.rs:67:24
247265
|
248266
LL | match_guarded_arm!((NonEmptyUnion1 { foo: () }));
249267
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyUnion1 { .. }` not covered
@@ -262,7 +280,7 @@ LL + NonEmptyUnion1 { .. } => todo!()
262280
|
263281

264282
error[E0004]: non-exhaustive patterns: `NonEmptyUnion2 { .. }` not covered
265-
--> $DIR/empty-match.rs:65:24
283+
--> $DIR/empty-match.rs:68:24
266284
|
267285
LL | match_guarded_arm!((NonEmptyUnion2 { foo: () }));
268286
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyUnion2 { .. }` not covered
@@ -282,7 +300,7 @@ LL + NonEmptyUnion2 { .. } => todo!()
282300
|
283301

284302
error[E0004]: non-exhaustive patterns: `NonEmptyEnum1::Foo(_)` not covered
285-
--> $DIR/empty-match.rs:66:24
303+
--> $DIR/empty-match.rs:69:24
286304
|
287305
LL | match_guarded_arm!(NonEmptyEnum1::Foo(true));
288306
| ^^^^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyEnum1::Foo(_)` not covered
@@ -303,7 +321,7 @@ LL + NonEmptyEnum1::Foo(_) => todo!()
303321
|
304322

305323
error[E0004]: non-exhaustive patterns: `NonEmptyEnum2::Foo(_)` and `NonEmptyEnum2::Bar` not covered
306-
--> $DIR/empty-match.rs:67:24
324+
--> $DIR/empty-match.rs:70:24
307325
|
308326
LL | match_guarded_arm!(NonEmptyEnum2::Foo(true));
309327
| ^^^^^^^^^^^^^^^^^^^^^^^^ patterns `NonEmptyEnum2::Foo(_)` and `NonEmptyEnum2::Bar` not covered
@@ -326,7 +344,7 @@ LL + NonEmptyEnum2::Foo(_) | NonEmptyEnum2::Bar => todo!()
326344
|
327345

328346
error[E0004]: non-exhaustive patterns: `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered
329-
--> $DIR/empty-match.rs:68:24
347+
--> $DIR/empty-match.rs:71:24
330348
|
331349
LL | match_guarded_arm!(NonEmptyEnum5::V1);
332350
| ^^^^^^^^^^^^^^^^^ patterns `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered
@@ -354,6 +372,34 @@ LL ~ _ if false => {},
354372
LL + _ => todo!()
355373
|
356374

357-
error: aborting due to 22 previous errors
375+
error[E0004]: non-exhaustive patterns: `[]` not covered
376+
--> $DIR/empty-match.rs:72:24
377+
|
378+
LL | match_guarded_arm!(array0_of_empty);
379+
| ^^^^^^^^^^^^^^^ pattern `[]` not covered
380+
|
381+
= note: the matched value is of type `[!; 0]`
382+
= note: match arms with guards don't count towards exhaustivity
383+
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
384+
|
385+
LL ~ _ if false => {},
386+
LL + [] => todo!()
387+
|
388+
389+
error[E0004]: non-exhaustive patterns: `[]` not covered
390+
--> $DIR/empty-match.rs:73:24
391+
|
392+
LL | match_guarded_arm!(arrayN_of_empty);
393+
| ^^^^^^^^^^^^^^^ pattern `[]` not covered
394+
|
395+
= note: the matched value is of type `[!; N]`
396+
= note: match arms with guards don't count towards exhaustivity
397+
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
398+
|
399+
LL ~ _ if false => {},
400+
LL + [] => todo!()
401+
|
402+
403+
error: aborting due to 26 previous errors
358404

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

0 commit comments

Comments
 (0)