Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 4e4a929

Browse files
committed
Test Result<!, !>
1 parent e87594e commit 4e4a929

File tree

3 files changed

+108
-34
lines changed

3 files changed

+108
-34
lines changed

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

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,20 @@ error: unreachable pattern
5555
LL | _ if false => {},
5656
| ^
5757

58+
error: unreachable pattern
59+
--> $DIR/empty-match.rs:102:9
60+
|
61+
LL | _ => {},
62+
| ^
63+
64+
error: unreachable pattern
65+
--> $DIR/empty-match.rs:110:9
66+
|
67+
LL | _ if false => {},
68+
| ^
69+
5870
error[E0004]: non-exhaustive patterns: type `u8` is non-empty
59-
--> $DIR/empty-match.rs:109:20
71+
--> $DIR/empty-match.rs:128:20
6072
|
6173
LL | match_no_arms!(0u8);
6274
| ^^^
@@ -65,7 +77,7 @@ LL | match_no_arms!(0u8);
6577
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern
6678

6779
error[E0004]: non-exhaustive patterns: type `NonEmptyStruct1` is non-empty
68-
--> $DIR/empty-match.rs:111:20
80+
--> $DIR/empty-match.rs:130:20
6981
|
7082
LL | match_no_arms!(NonEmptyStruct1);
7183
| ^^^^^^^^^^^^^^^
@@ -79,7 +91,7 @@ LL | struct NonEmptyStruct1;
7991
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern
8092

8193
error[E0004]: non-exhaustive patterns: type `NonEmptyStruct2` is non-empty
82-
--> $DIR/empty-match.rs:113:20
94+
--> $DIR/empty-match.rs:132:20
8395
|
8496
LL | match_no_arms!(NonEmptyStruct2(true));
8597
| ^^^^^^^^^^^^^^^^^^^^^
@@ -93,7 +105,7 @@ LL | struct NonEmptyStruct2(bool);
93105
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern
94106

95107
error[E0004]: non-exhaustive patterns: type `NonEmptyUnion1` is non-empty
96-
--> $DIR/empty-match.rs:115:20
108+
--> $DIR/empty-match.rs:134:20
97109
|
98110
LL | match_no_arms!((NonEmptyUnion1 { foo: () }));
99111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -107,7 +119,7 @@ LL | union NonEmptyUnion1 {
107119
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern
108120

109121
error[E0004]: non-exhaustive patterns: type `NonEmptyUnion2` is non-empty
110-
--> $DIR/empty-match.rs:117:20
122+
--> $DIR/empty-match.rs:136:20
111123
|
112124
LL | match_no_arms!((NonEmptyUnion2 { foo: () }));
113125
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -121,7 +133,7 @@ LL | union NonEmptyUnion2 {
121133
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern
122134

123135
error[E0004]: non-exhaustive patterns: `NonEmptyEnum1::Foo(_)` not covered
124-
--> $DIR/empty-match.rs:119:20
136+
--> $DIR/empty-match.rs:138:20
125137
|
126138
LL | match_no_arms!(NonEmptyEnum1::Foo(true));
127139
| ^^^^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyEnum1::Foo(_)` not covered
@@ -137,7 +149,7 @@ LL | Foo(bool),
137149
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern
138150

139151
error[E0004]: non-exhaustive patterns: `NonEmptyEnum2::Foo(_)` and `NonEmptyEnum2::Bar` not covered
140-
--> $DIR/empty-match.rs:122:20
152+
--> $DIR/empty-match.rs:141:20
141153
|
142154
LL | match_no_arms!(NonEmptyEnum2::Foo(true));
143155
| ^^^^^^^^^^^^^^^^^^^^^^^^ patterns `NonEmptyEnum2::Foo(_)` and `NonEmptyEnum2::Bar` not covered
@@ -156,7 +168,7 @@ LL | Bar,
156168
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or multiple match arms
157169

158170
error[E0004]: non-exhaustive patterns: `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered
159-
--> $DIR/empty-match.rs:125:20
171+
--> $DIR/empty-match.rs:144:20
160172
|
161173
LL | match_no_arms!(NonEmptyEnum5::V1);
162174
| ^^^^^^^^^^^^^^^^^ patterns `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered
@@ -170,7 +182,7 @@ LL | enum NonEmptyEnum5 {
170182
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or multiple match arms
171183

172184
error[E0004]: non-exhaustive patterns: `_` not covered
173-
--> $DIR/empty-match.rs:129:24
185+
--> $DIR/empty-match.rs:148:24
174186
|
175187
LL | match_guarded_arm!(0u8);
176188
| ^^^ pattern `_` not covered
@@ -184,7 +196,7 @@ LL + _ => todo!()
184196
|
185197

186198
error[E0004]: non-exhaustive patterns: `NonEmptyStruct1` not covered
187-
--> $DIR/empty-match.rs:134:24
199+
--> $DIR/empty-match.rs:153:24
188200
|
189201
LL | match_guarded_arm!(NonEmptyStruct1);
190202
| ^^^^^^^^^^^^^^^ pattern `NonEmptyStruct1` not covered
@@ -203,7 +215,7 @@ LL + NonEmptyStruct1 => todo!()
203215
|
204216

205217
error[E0004]: non-exhaustive patterns: `NonEmptyStruct2(_)` not covered
206-
--> $DIR/empty-match.rs:139:24
218+
--> $DIR/empty-match.rs:158:24
207219
|
208220
LL | match_guarded_arm!(NonEmptyStruct2(true));
209221
| ^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyStruct2(_)` not covered
@@ -222,7 +234,7 @@ LL + NonEmptyStruct2(_) => todo!()
222234
|
223235

224236
error[E0004]: non-exhaustive patterns: `NonEmptyUnion1 { .. }` not covered
225-
--> $DIR/empty-match.rs:144:24
237+
--> $DIR/empty-match.rs:163:24
226238
|
227239
LL | match_guarded_arm!((NonEmptyUnion1 { foo: () }));
228240
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyUnion1 { .. }` not covered
@@ -241,7 +253,7 @@ LL + NonEmptyUnion1 { .. } => todo!()
241253
|
242254

243255
error[E0004]: non-exhaustive patterns: `NonEmptyUnion2 { .. }` not covered
244-
--> $DIR/empty-match.rs:149:24
256+
--> $DIR/empty-match.rs:168:24
245257
|
246258
LL | match_guarded_arm!((NonEmptyUnion2 { foo: () }));
247259
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyUnion2 { .. }` not covered
@@ -260,7 +272,7 @@ LL + NonEmptyUnion2 { .. } => todo!()
260272
|
261273

262274
error[E0004]: non-exhaustive patterns: `NonEmptyEnum1::Foo(_)` not covered
263-
--> $DIR/empty-match.rs:154:24
275+
--> $DIR/empty-match.rs:173:24
264276
|
265277
LL | match_guarded_arm!(NonEmptyEnum1::Foo(true));
266278
| ^^^^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyEnum1::Foo(_)` not covered
@@ -281,7 +293,7 @@ LL + NonEmptyEnum1::Foo(_) => todo!()
281293
|
282294

283295
error[E0004]: non-exhaustive patterns: `NonEmptyEnum2::Foo(_)` and `NonEmptyEnum2::Bar` not covered
284-
--> $DIR/empty-match.rs:159:24
296+
--> $DIR/empty-match.rs:178:24
285297
|
286298
LL | match_guarded_arm!(NonEmptyEnum2::Foo(true));
287299
| ^^^^^^^^^^^^^^^^^^^^^^^^ patterns `NonEmptyEnum2::Foo(_)` and `NonEmptyEnum2::Bar` not covered
@@ -305,7 +317,7 @@ LL + NonEmptyEnum2::Foo(_) | NonEmptyEnum2::Bar => todo!()
305317
|
306318

307319
error[E0004]: non-exhaustive patterns: `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered
308-
--> $DIR/empty-match.rs:164:24
320+
--> $DIR/empty-match.rs:183:24
309321
|
310322
LL | match_guarded_arm!(NonEmptyEnum5::V1);
311323
| ^^^^^^^^^^^^^^^^^ patterns `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered
@@ -323,7 +335,7 @@ LL ~ _ if false => {},
323335
LL + _ => todo!()
324336
|
325337

326-
error: aborting due to 23 previous errors
338+
error: aborting due to 25 previous errors
327339

328340
Some errors have detailed explanations: E0004, E0005.
329341
For more information about an error, try `rustc --explain E0004`.

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

Lines changed: 60 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,51 @@ error: unreachable pattern
5454
LL | _ if false => {},
5555
| ^
5656

57+
error[E0004]: non-exhaustive patterns: `Ok(_)` and `Err(_)` not covered
58+
--> $DIR/empty-match.rs:96:11
59+
|
60+
LL | match x {} // ok
61+
| ^ patterns `Ok(_)` and `Err(_)` not covered
62+
|
63+
note: `Result<!, !>` defined here
64+
--> $SRC_DIR/core/src/result.rs:LL:COL
65+
::: $SRC_DIR/core/src/result.rs:LL:COL
66+
|
67+
= note: not covered
68+
::: $SRC_DIR/core/src/result.rs:LL:COL
69+
|
70+
= note: not covered
71+
= note: the matched value is of type `Result<!, !>`
72+
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern, a match arm with multiple or-patterns as shown, or multiple match arms
73+
|
74+
LL ~ match x {
75+
LL + Ok(_) | Err(_) => todo!(),
76+
LL ~ } // ok
77+
|
78+
79+
error[E0004]: non-exhaustive patterns: `Ok(_)` and `Err(_)` not covered
80+
--> $DIR/empty-match.rs:104:11
81+
|
82+
LL | match x {
83+
| ^ patterns `Ok(_)` and `Err(_)` not covered
84+
|
85+
note: `Result<!, !>` defined here
86+
--> $SRC_DIR/core/src/result.rs:LL:COL
87+
::: $SRC_DIR/core/src/result.rs:LL:COL
88+
|
89+
= note: not covered
90+
::: $SRC_DIR/core/src/result.rs:LL:COL
91+
|
92+
= note: not covered
93+
= note: the matched value is of type `Result<!, !>`
94+
= note: match arms with guards don't count towards exhaustivity
95+
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern, a match arm with multiple or-patterns as shown, or multiple match arms
96+
|
97+
LL | _ if false => {}, Ok(_) | Err(_) => todo!(),
98+
| +++++++++++++++++++++++++++
99+
57100
error[E0004]: non-exhaustive patterns: type `u8` is non-empty
58-
--> $DIR/empty-match.rs:109:20
101+
--> $DIR/empty-match.rs:128:20
59102
|
60103
LL | match_no_arms!(0u8);
61104
| ^^^
@@ -64,7 +107,7 @@ LL | match_no_arms!(0u8);
64107
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern
65108

66109
error[E0004]: non-exhaustive patterns: type `NonEmptyStruct1` is non-empty
67-
--> $DIR/empty-match.rs:111:20
110+
--> $DIR/empty-match.rs:130:20
68111
|
69112
LL | match_no_arms!(NonEmptyStruct1);
70113
| ^^^^^^^^^^^^^^^
@@ -78,7 +121,7 @@ LL | struct NonEmptyStruct1;
78121
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern
79122

80123
error[E0004]: non-exhaustive patterns: type `NonEmptyStruct2` is non-empty
81-
--> $DIR/empty-match.rs:113:20
124+
--> $DIR/empty-match.rs:132:20
82125
|
83126
LL | match_no_arms!(NonEmptyStruct2(true));
84127
| ^^^^^^^^^^^^^^^^^^^^^
@@ -92,7 +135,7 @@ LL | struct NonEmptyStruct2(bool);
92135
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern
93136

94137
error[E0004]: non-exhaustive patterns: type `NonEmptyUnion1` is non-empty
95-
--> $DIR/empty-match.rs:115:20
138+
--> $DIR/empty-match.rs:134:20
96139
|
97140
LL | match_no_arms!((NonEmptyUnion1 { foo: () }));
98141
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -106,7 +149,7 @@ LL | union NonEmptyUnion1 {
106149
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern
107150

108151
error[E0004]: non-exhaustive patterns: type `NonEmptyUnion2` is non-empty
109-
--> $DIR/empty-match.rs:117:20
152+
--> $DIR/empty-match.rs:136:20
110153
|
111154
LL | match_no_arms!((NonEmptyUnion2 { foo: () }));
112155
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -120,7 +163,7 @@ LL | union NonEmptyUnion2 {
120163
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern
121164

122165
error[E0004]: non-exhaustive patterns: `NonEmptyEnum1::Foo(_)` not covered
123-
--> $DIR/empty-match.rs:119:20
166+
--> $DIR/empty-match.rs:138:20
124167
|
125168
LL | match_no_arms!(NonEmptyEnum1::Foo(true));
126169
| ^^^^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyEnum1::Foo(_)` not covered
@@ -136,7 +179,7 @@ LL | Foo(bool),
136179
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern
137180

138181
error[E0004]: non-exhaustive patterns: `NonEmptyEnum2::Foo(_)` and `NonEmptyEnum2::Bar` not covered
139-
--> $DIR/empty-match.rs:122:20
182+
--> $DIR/empty-match.rs:141:20
140183
|
141184
LL | match_no_arms!(NonEmptyEnum2::Foo(true));
142185
| ^^^^^^^^^^^^^^^^^^^^^^^^ patterns `NonEmptyEnum2::Foo(_)` and `NonEmptyEnum2::Bar` not covered
@@ -155,7 +198,7 @@ LL | Bar,
155198
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or multiple match arms
156199

157200
error[E0004]: non-exhaustive patterns: `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered
158-
--> $DIR/empty-match.rs:125:20
201+
--> $DIR/empty-match.rs:144:20
159202
|
160203
LL | match_no_arms!(NonEmptyEnum5::V1);
161204
| ^^^^^^^^^^^^^^^^^ patterns `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered
@@ -169,7 +212,7 @@ LL | enum NonEmptyEnum5 {
169212
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or multiple match arms
170213

171214
error[E0004]: non-exhaustive patterns: `_` not covered
172-
--> $DIR/empty-match.rs:129:24
215+
--> $DIR/empty-match.rs:148:24
173216
|
174217
LL | match_guarded_arm!(0u8);
175218
| ^^^ pattern `_` not covered
@@ -183,7 +226,7 @@ LL + _ => todo!()
183226
|
184227

185228
error[E0004]: non-exhaustive patterns: `NonEmptyStruct1` not covered
186-
--> $DIR/empty-match.rs:134:24
229+
--> $DIR/empty-match.rs:153:24
187230
|
188231
LL | match_guarded_arm!(NonEmptyStruct1);
189232
| ^^^^^^^^^^^^^^^ pattern `NonEmptyStruct1` not covered
@@ -202,7 +245,7 @@ LL + NonEmptyStruct1 => todo!()
202245
|
203246

204247
error[E0004]: non-exhaustive patterns: `NonEmptyStruct2(_)` not covered
205-
--> $DIR/empty-match.rs:139:24
248+
--> $DIR/empty-match.rs:158:24
206249
|
207250
LL | match_guarded_arm!(NonEmptyStruct2(true));
208251
| ^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyStruct2(_)` not covered
@@ -221,7 +264,7 @@ LL + NonEmptyStruct2(_) => todo!()
221264
|
222265

223266
error[E0004]: non-exhaustive patterns: `NonEmptyUnion1 { .. }` not covered
224-
--> $DIR/empty-match.rs:144:24
267+
--> $DIR/empty-match.rs:163:24
225268
|
226269
LL | match_guarded_arm!((NonEmptyUnion1 { foo: () }));
227270
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyUnion1 { .. }` not covered
@@ -240,7 +283,7 @@ LL + NonEmptyUnion1 { .. } => todo!()
240283
|
241284

242285
error[E0004]: non-exhaustive patterns: `NonEmptyUnion2 { .. }` not covered
243-
--> $DIR/empty-match.rs:149:24
286+
--> $DIR/empty-match.rs:168:24
244287
|
245288
LL | match_guarded_arm!((NonEmptyUnion2 { foo: () }));
246289
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyUnion2 { .. }` not covered
@@ -259,7 +302,7 @@ LL + NonEmptyUnion2 { .. } => todo!()
259302
|
260303

261304
error[E0004]: non-exhaustive patterns: `NonEmptyEnum1::Foo(_)` not covered
262-
--> $DIR/empty-match.rs:154:24
305+
--> $DIR/empty-match.rs:173:24
263306
|
264307
LL | match_guarded_arm!(NonEmptyEnum1::Foo(true));
265308
| ^^^^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyEnum1::Foo(_)` not covered
@@ -280,7 +323,7 @@ LL + NonEmptyEnum1::Foo(_) => todo!()
280323
|
281324

282325
error[E0004]: non-exhaustive patterns: `NonEmptyEnum2::Foo(_)` and `NonEmptyEnum2::Bar` not covered
283-
--> $DIR/empty-match.rs:159:24
326+
--> $DIR/empty-match.rs:178:24
284327
|
285328
LL | match_guarded_arm!(NonEmptyEnum2::Foo(true));
286329
| ^^^^^^^^^^^^^^^^^^^^^^^^ patterns `NonEmptyEnum2::Foo(_)` and `NonEmptyEnum2::Bar` not covered
@@ -304,7 +347,7 @@ LL + NonEmptyEnum2::Foo(_) | NonEmptyEnum2::Bar => todo!()
304347
|
305348

306349
error[E0004]: non-exhaustive patterns: `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered
307-
--> $DIR/empty-match.rs:164:24
350+
--> $DIR/empty-match.rs:183:24
308351
|
309352
LL | match_guarded_arm!(NonEmptyEnum5::V1);
310353
| ^^^^^^^^^^^^^^^^^ patterns `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered
@@ -322,7 +365,7 @@ LL ~ _ if false => {},
322365
LL + _ => todo!()
323366
|
324367

325-
error: aborting due to 23 previous errors
368+
error: aborting due to 25 previous errors
326369

327370
Some errors have detailed explanations: E0004, E0005.
328371
For more information about an error, try `rustc --explain E0004`.

tests/ui/pattern/usefulness/empty-match.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,25 @@ fn never(x: !) {
9292
}
9393
}
9494

95+
fn nested_never(x: Result<!, !>) {
96+
match x {} // ok
97+
//[normal]~^ ERROR `Ok(_)` and `Err(_)` not covered
98+
//[normal]~| NOTE not covered
99+
//[normal]~| NOTE the matched value is of type
100+
//[normal]~| NOTE defined here
101+
match x {
102+
_ => {}, //[exhaustive_patterns]~ ERROR unreachable pattern
103+
}
104+
match x {
105+
//[normal]~^ ERROR `Ok(_)` and `Err(_)` not covered
106+
//[normal]~| NOTE not covered
107+
//[normal]~| NOTE the matched value is of type
108+
//[normal]~| NOTE defined here
109+
//[normal]~| NOTE match arms with guards don't count towards exhaustivity
110+
_ if false => {}, //[exhaustive_patterns]~ ERROR unreachable pattern
111+
}
112+
}
113+
95114
macro_rules! match_no_arms {
96115
($e:expr) => {
97116
match $e {}

0 commit comments

Comments
 (0)