Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit dd74ae0

Browse files
authoredMay 26, 2023
Rollup merge of #111951 - cjgillot:uninh-comment, r=Nadrieril
Correct comment on privately uninhabited pattern. Follow-up to #111624 (comment) r? `@Nadrieril`
2 parents 39b633e + ee27c49 commit dd74ae0

File tree

4 files changed

+179
-78
lines changed

4 files changed

+179
-78
lines changed
 

‎compiler/rustc_mir_build/src/thir/pattern/check_match.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,8 @@ impl<'p, 'tcx> MatchVisitor<'_, 'p, 'tcx> {
491491
AdtDefinedHere { adt_def_span, ty, variants }
492492
};
493493

494-
// Emit an extra note if the first uncovered witness is
495-
// visibly uninhabited anywhere in the current crate.
494+
// Emit an extra note if the first uncovered witness would be uninhabited
495+
// if we disregard visibility.
496496
let witness_1_is_privately_uninhabited =
497497
if cx.tcx.features().exhaustive_patterns
498498
&& let Some(witness_1) = witnesses.get(0)

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

Lines changed: 56 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: unreachable pattern
2-
--> $DIR/empty-match.rs:37:9
2+
--> $DIR/empty-match.rs:58:9
33
|
44
LL | _ => {},
55
| ^
@@ -11,37 +11,52 @@ LL | #![deny(unreachable_patterns)]
1111
| ^^^^^^^^^^^^^^^^^^^^
1212

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

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

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

31+
error[E0005]: refutable pattern in local binding
32+
--> $DIR/empty-match.rs:76: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+
3146
error: unreachable pattern
32-
--> $DIR/empty-match.rs:57:9
47+
--> $DIR/empty-match.rs:88:9
3348
|
3449
LL | _ => {},
3550
| ^
3651

3752
error: unreachable pattern
38-
--> $DIR/empty-match.rs:60:9
53+
--> $DIR/empty-match.rs:91:9
3954
|
4055
LL | _ if false => {},
4156
| ^
4257

4358
error[E0004]: non-exhaustive patterns: type `u8` is non-empty
44-
--> $DIR/empty-match.rs:78:20
59+
--> $DIR/empty-match.rs:109:20
4560
|
4661
LL | match_no_arms!(0u8);
4762
| ^^^
@@ -50,69 +65,69 @@ LL | match_no_arms!(0u8);
5065
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern
5166

5267
error[E0004]: non-exhaustive patterns: type `NonEmptyStruct1` is non-empty
53-
--> $DIR/empty-match.rs:79:20
68+
--> $DIR/empty-match.rs:111:20
5469
|
5570
LL | match_no_arms!(NonEmptyStruct1);
5671
| ^^^^^^^^^^^^^^^
5772
|
5873
note: `NonEmptyStruct1` defined here
59-
--> $DIR/empty-match.rs:14:8
74+
--> $DIR/empty-match.rs:15:8
6075
|
6176
LL | struct NonEmptyStruct1;
6277
| ^^^^^^^^^^^^^^^
6378
= note: the matched value is of type `NonEmptyStruct1`
6479
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern
6580

6681
error[E0004]: non-exhaustive patterns: type `NonEmptyStruct2` is non-empty
67-
--> $DIR/empty-match.rs:80:20
82+
--> $DIR/empty-match.rs:113:20
6883
|
6984
LL | match_no_arms!(NonEmptyStruct2(true));
7085
| ^^^^^^^^^^^^^^^^^^^^^
7186
|
7287
note: `NonEmptyStruct2` defined here
73-
--> $DIR/empty-match.rs:15:8
88+
--> $DIR/empty-match.rs:18:8
7489
|
7590
LL | struct NonEmptyStruct2(bool);
7691
| ^^^^^^^^^^^^^^^
7792
= note: the matched value is of type `NonEmptyStruct2`
7893
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern
7994

8095
error[E0004]: non-exhaustive patterns: type `NonEmptyUnion1` is non-empty
81-
--> $DIR/empty-match.rs:81:20
96+
--> $DIR/empty-match.rs:115:20
8297
|
8398
LL | match_no_arms!((NonEmptyUnion1 { foo: () }));
8499
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
85100
|
86101
note: `NonEmptyUnion1` defined here
87-
--> $DIR/empty-match.rs:16:7
102+
--> $DIR/empty-match.rs:21:7
88103
|
89104
LL | union NonEmptyUnion1 {
90105
| ^^^^^^^^^^^^^^
91106
= note: the matched value is of type `NonEmptyUnion1`
92107
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern
93108

94109
error[E0004]: non-exhaustive patterns: type `NonEmptyUnion2` is non-empty
95-
--> $DIR/empty-match.rs:82:20
110+
--> $DIR/empty-match.rs:117:20
96111
|
97112
LL | match_no_arms!((NonEmptyUnion2 { foo: () }));
98113
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
99114
|
100115
note: `NonEmptyUnion2` defined here
101-
--> $DIR/empty-match.rs:19:7
116+
--> $DIR/empty-match.rs:26:7
102117
|
103118
LL | union NonEmptyUnion2 {
104119
| ^^^^^^^^^^^^^^
105120
= note: the matched value is of type `NonEmptyUnion2`
106121
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern
107122

108123
error[E0004]: non-exhaustive patterns: `NonEmptyEnum1::Foo(_)` not covered
109-
--> $DIR/empty-match.rs:83:20
124+
--> $DIR/empty-match.rs:119:20
110125
|
111126
LL | match_no_arms!(NonEmptyEnum1::Foo(true));
112127
| ^^^^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyEnum1::Foo(_)` not covered
113128
|
114129
note: `NonEmptyEnum1` defined here
115-
--> $DIR/empty-match.rs:24:5
130+
--> $DIR/empty-match.rs:33:5
116131
|
117132
LL | enum NonEmptyEnum1 {
118133
| -------------
@@ -122,39 +137,40 @@ LL | Foo(bool),
122137
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern
123138

124139
error[E0004]: non-exhaustive patterns: `NonEmptyEnum2::Foo(_)` and `NonEmptyEnum2::Bar` not covered
125-
--> $DIR/empty-match.rs:84:20
140+
--> $DIR/empty-match.rs:122:20
126141
|
127142
LL | match_no_arms!(NonEmptyEnum2::Foo(true));
128143
| ^^^^^^^^^^^^^^^^^^^^^^^^ patterns `NonEmptyEnum2::Foo(_)` and `NonEmptyEnum2::Bar` not covered
129144
|
130145
note: `NonEmptyEnum2` defined here
131-
--> $DIR/empty-match.rs:27:5
146+
--> $DIR/empty-match.rs:40:5
132147
|
133148
LL | enum NonEmptyEnum2 {
134149
| -------------
135150
LL | Foo(bool),
136151
| ^^^ not covered
152+
...
137153
LL | Bar,
138154
| ^^^ not covered
139155
= note: the matched value is of type `NonEmptyEnum2`
140156
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or multiple match arms
141157

142158
error[E0004]: non-exhaustive patterns: `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered
143-
--> $DIR/empty-match.rs:85:20
159+
--> $DIR/empty-match.rs:125:20
144160
|
145161
LL | match_no_arms!(NonEmptyEnum5::V1);
146162
| ^^^^^^^^^^^^^^^^^ patterns `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered
147163
|
148164
note: `NonEmptyEnum5` defined here
149-
--> $DIR/empty-match.rs:30:6
165+
--> $DIR/empty-match.rs:49:6
150166
|
151167
LL | enum NonEmptyEnum5 {
152168
| ^^^^^^^^^^^^^
153169
= note: the matched value is of type `NonEmptyEnum5`
154170
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or multiple match arms
155171

156172
error[E0004]: non-exhaustive patterns: `_` not covered
157-
--> $DIR/empty-match.rs:87:24
173+
--> $DIR/empty-match.rs:129:24
158174
|
159175
LL | match_guarded_arm!(0u8);
160176
| ^^^ pattern `_` not covered
@@ -167,13 +183,13 @@ LL + _ => todo!()
167183
|
168184

169185
error[E0004]: non-exhaustive patterns: `NonEmptyStruct1` not covered
170-
--> $DIR/empty-match.rs:88:24
186+
--> $DIR/empty-match.rs:133:24
171187
|
172188
LL | match_guarded_arm!(NonEmptyStruct1);
173189
| ^^^^^^^^^^^^^^^ pattern `NonEmptyStruct1` not covered
174190
|
175191
note: `NonEmptyStruct1` defined here
176-
--> $DIR/empty-match.rs:14:8
192+
--> $DIR/empty-match.rs:15:8
177193
|
178194
LL | struct NonEmptyStruct1;
179195
| ^^^^^^^^^^^^^^^
@@ -185,13 +201,13 @@ LL + NonEmptyStruct1 => todo!()
185201
|
186202

187203
error[E0004]: non-exhaustive patterns: `NonEmptyStruct2(_)` not covered
188-
--> $DIR/empty-match.rs:89:24
204+
--> $DIR/empty-match.rs:137:24
189205
|
190206
LL | match_guarded_arm!(NonEmptyStruct2(true));
191207
| ^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyStruct2(_)` not covered
192208
|
193209
note: `NonEmptyStruct2` defined here
194-
--> $DIR/empty-match.rs:15:8
210+
--> $DIR/empty-match.rs:18:8
195211
|
196212
LL | struct NonEmptyStruct2(bool);
197213
| ^^^^^^^^^^^^^^^
@@ -203,13 +219,13 @@ LL + NonEmptyStruct2(_) => todo!()
203219
|
204220

205221
error[E0004]: non-exhaustive patterns: `NonEmptyUnion1 { .. }` not covered
206-
--> $DIR/empty-match.rs:90:24
222+
--> $DIR/empty-match.rs:141:24
207223
|
208224
LL | match_guarded_arm!((NonEmptyUnion1 { foo: () }));
209225
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyUnion1 { .. }` not covered
210226
|
211227
note: `NonEmptyUnion1` defined here
212-
--> $DIR/empty-match.rs:16:7
228+
--> $DIR/empty-match.rs:21:7
213229
|
214230
LL | union NonEmptyUnion1 {
215231
| ^^^^^^^^^^^^^^
@@ -221,13 +237,13 @@ LL + NonEmptyUnion1 { .. } => todo!()
221237
|
222238

223239
error[E0004]: non-exhaustive patterns: `NonEmptyUnion2 { .. }` not covered
224-
--> $DIR/empty-match.rs:91:24
240+
--> $DIR/empty-match.rs:145:24
225241
|
226242
LL | match_guarded_arm!((NonEmptyUnion2 { foo: () }));
227243
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyUnion2 { .. }` not covered
228244
|
229245
note: `NonEmptyUnion2` defined here
230-
--> $DIR/empty-match.rs:19:7
246+
--> $DIR/empty-match.rs:26:7
231247
|
232248
LL | union NonEmptyUnion2 {
233249
| ^^^^^^^^^^^^^^
@@ -239,13 +255,13 @@ LL + NonEmptyUnion2 { .. } => todo!()
239255
|
240256

241257
error[E0004]: non-exhaustive patterns: `NonEmptyEnum1::Foo(_)` not covered
242-
--> $DIR/empty-match.rs:92:24
258+
--> $DIR/empty-match.rs:149:24
243259
|
244260
LL | match_guarded_arm!(NonEmptyEnum1::Foo(true));
245261
| ^^^^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyEnum1::Foo(_)` not covered
246262
|
247263
note: `NonEmptyEnum1` defined here
248-
--> $DIR/empty-match.rs:24:5
264+
--> $DIR/empty-match.rs:33:5
249265
|
250266
LL | enum NonEmptyEnum1 {
251267
| -------------
@@ -259,18 +275,19 @@ LL + NonEmptyEnum1::Foo(_) => todo!()
259275
|
260276

261277
error[E0004]: non-exhaustive patterns: `NonEmptyEnum2::Foo(_)` and `NonEmptyEnum2::Bar` not covered
262-
--> $DIR/empty-match.rs:93:24
278+
--> $DIR/empty-match.rs:153:24
263279
|
264280
LL | match_guarded_arm!(NonEmptyEnum2::Foo(true));
265281
| ^^^^^^^^^^^^^^^^^^^^^^^^ patterns `NonEmptyEnum2::Foo(_)` and `NonEmptyEnum2::Bar` not covered
266282
|
267283
note: `NonEmptyEnum2` defined here
268-
--> $DIR/empty-match.rs:27:5
284+
--> $DIR/empty-match.rs:40:5
269285
|
270286
LL | enum NonEmptyEnum2 {
271287
| -------------
272288
LL | Foo(bool),
273289
| ^^^ not covered
290+
...
274291
LL | Bar,
275292
| ^^^ not covered
276293
= note: the matched value is of type `NonEmptyEnum2`
@@ -281,13 +298,13 @@ LL + NonEmptyEnum2::Foo(_) | NonEmptyEnum2::Bar => todo!()
281298
|
282299

283300
error[E0004]: non-exhaustive patterns: `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered
284-
--> $DIR/empty-match.rs:94:24
301+
--> $DIR/empty-match.rs:157:24
285302
|
286303
LL | match_guarded_arm!(NonEmptyEnum5::V1);
287304
| ^^^^^^^^^^^^^^^^^ patterns `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered
288305
|
289306
note: `NonEmptyEnum5` defined here
290-
--> $DIR/empty-match.rs:30:6
307+
--> $DIR/empty-match.rs:49:6
291308
|
292309
LL | enum NonEmptyEnum5 {
293310
| ^^^^^^^^^^^^^
@@ -298,6 +315,7 @@ LL ~ _ if false => {},
298315
LL + _ => todo!()
299316
|
300317

301-
error: aborting due to 22 previous errors
318+
error: aborting due to 23 previous errors
302319

303-
For more information about this error, try `rustc --explain E0004`.
320+
Some errors have detailed explanations: E0004, E0005.
321+
For more information about an error, try `rustc --explain E0004`.

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

Lines changed: 55 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: unreachable pattern
2-
--> $DIR/empty-match.rs:37:9
2+
--> $DIR/empty-match.rs:58:9
33
|
44
LL | _ => {},
55
| ^
@@ -11,37 +11,51 @@ LL | #![deny(unreachable_patterns)]
1111
| ^^^^^^^^^^^^^^^^^^^^
1212

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

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

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

31+
error[E0005]: refutable pattern in local binding
32+
--> $DIR/empty-match.rs:76: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+
3145
error: unreachable pattern
32-
--> $DIR/empty-match.rs:57:9
46+
--> $DIR/empty-match.rs:88:9
3347
|
3448
LL | _ => {},
3549
| ^
3650

3751
error: unreachable pattern
38-
--> $DIR/empty-match.rs:60:9
52+
--> $DIR/empty-match.rs:91:9
3953
|
4054
LL | _ if false => {},
4155
| ^
4256

4357
error[E0004]: non-exhaustive patterns: type `u8` is non-empty
44-
--> $DIR/empty-match.rs:78:20
58+
--> $DIR/empty-match.rs:109:20
4559
|
4660
LL | match_no_arms!(0u8);
4761
| ^^^
@@ -50,69 +64,69 @@ LL | match_no_arms!(0u8);
5064
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern
5165

5266
error[E0004]: non-exhaustive patterns: type `NonEmptyStruct1` is non-empty
53-
--> $DIR/empty-match.rs:79:20
67+
--> $DIR/empty-match.rs:111:20
5468
|
5569
LL | match_no_arms!(NonEmptyStruct1);
5670
| ^^^^^^^^^^^^^^^
5771
|
5872
note: `NonEmptyStruct1` defined here
59-
--> $DIR/empty-match.rs:14:8
73+
--> $DIR/empty-match.rs:15:8
6074
|
6175
LL | struct NonEmptyStruct1;
6276
| ^^^^^^^^^^^^^^^
6377
= note: the matched value is of type `NonEmptyStruct1`
6478
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern
6579

6680
error[E0004]: non-exhaustive patterns: type `NonEmptyStruct2` is non-empty
67-
--> $DIR/empty-match.rs:80:20
81+
--> $DIR/empty-match.rs:113:20
6882
|
6983
LL | match_no_arms!(NonEmptyStruct2(true));
7084
| ^^^^^^^^^^^^^^^^^^^^^
7185
|
7286
note: `NonEmptyStruct2` defined here
73-
--> $DIR/empty-match.rs:15:8
87+
--> $DIR/empty-match.rs:18:8
7488
|
7589
LL | struct NonEmptyStruct2(bool);
7690
| ^^^^^^^^^^^^^^^
7791
= note: the matched value is of type `NonEmptyStruct2`
7892
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern
7993

8094
error[E0004]: non-exhaustive patterns: type `NonEmptyUnion1` is non-empty
81-
--> $DIR/empty-match.rs:81:20
95+
--> $DIR/empty-match.rs:115:20
8296
|
8397
LL | match_no_arms!((NonEmptyUnion1 { foo: () }));
8498
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8599
|
86100
note: `NonEmptyUnion1` defined here
87-
--> $DIR/empty-match.rs:16:7
101+
--> $DIR/empty-match.rs:21:7
88102
|
89103
LL | union NonEmptyUnion1 {
90104
| ^^^^^^^^^^^^^^
91105
= note: the matched value is of type `NonEmptyUnion1`
92106
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern
93107

94108
error[E0004]: non-exhaustive patterns: type `NonEmptyUnion2` is non-empty
95-
--> $DIR/empty-match.rs:82:20
109+
--> $DIR/empty-match.rs:117:20
96110
|
97111
LL | match_no_arms!((NonEmptyUnion2 { foo: () }));
98112
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
99113
|
100114
note: `NonEmptyUnion2` defined here
101-
--> $DIR/empty-match.rs:19:7
115+
--> $DIR/empty-match.rs:26:7
102116
|
103117
LL | union NonEmptyUnion2 {
104118
| ^^^^^^^^^^^^^^
105119
= note: the matched value is of type `NonEmptyUnion2`
106120
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern
107121

108122
error[E0004]: non-exhaustive patterns: `NonEmptyEnum1::Foo(_)` not covered
109-
--> $DIR/empty-match.rs:83:20
123+
--> $DIR/empty-match.rs:119:20
110124
|
111125
LL | match_no_arms!(NonEmptyEnum1::Foo(true));
112126
| ^^^^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyEnum1::Foo(_)` not covered
113127
|
114128
note: `NonEmptyEnum1` defined here
115-
--> $DIR/empty-match.rs:24:5
129+
--> $DIR/empty-match.rs:33:5
116130
|
117131
LL | enum NonEmptyEnum1 {
118132
| -------------
@@ -122,39 +136,40 @@ LL | Foo(bool),
122136
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern
123137

124138
error[E0004]: non-exhaustive patterns: `NonEmptyEnum2::Foo(_)` and `NonEmptyEnum2::Bar` not covered
125-
--> $DIR/empty-match.rs:84:20
139+
--> $DIR/empty-match.rs:122:20
126140
|
127141
LL | match_no_arms!(NonEmptyEnum2::Foo(true));
128142
| ^^^^^^^^^^^^^^^^^^^^^^^^ patterns `NonEmptyEnum2::Foo(_)` and `NonEmptyEnum2::Bar` not covered
129143
|
130144
note: `NonEmptyEnum2` defined here
131-
--> $DIR/empty-match.rs:27:5
145+
--> $DIR/empty-match.rs:40:5
132146
|
133147
LL | enum NonEmptyEnum2 {
134148
| -------------
135149
LL | Foo(bool),
136150
| ^^^ not covered
151+
...
137152
LL | Bar,
138153
| ^^^ not covered
139154
= note: the matched value is of type `NonEmptyEnum2`
140155
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or multiple match arms
141156

142157
error[E0004]: non-exhaustive patterns: `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered
143-
--> $DIR/empty-match.rs:85:20
158+
--> $DIR/empty-match.rs:125:20
144159
|
145160
LL | match_no_arms!(NonEmptyEnum5::V1);
146161
| ^^^^^^^^^^^^^^^^^ patterns `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered
147162
|
148163
note: `NonEmptyEnum5` defined here
149-
--> $DIR/empty-match.rs:30:6
164+
--> $DIR/empty-match.rs:49:6
150165
|
151166
LL | enum NonEmptyEnum5 {
152167
| ^^^^^^^^^^^^^
153168
= note: the matched value is of type `NonEmptyEnum5`
154169
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or multiple match arms
155170

156171
error[E0004]: non-exhaustive patterns: `_` not covered
157-
--> $DIR/empty-match.rs:87:24
172+
--> $DIR/empty-match.rs:129:24
158173
|
159174
LL | match_guarded_arm!(0u8);
160175
| ^^^ pattern `_` not covered
@@ -167,13 +182,13 @@ LL + _ => todo!()
167182
|
168183

169184
error[E0004]: non-exhaustive patterns: `NonEmptyStruct1` not covered
170-
--> $DIR/empty-match.rs:88:24
185+
--> $DIR/empty-match.rs:133:24
171186
|
172187
LL | match_guarded_arm!(NonEmptyStruct1);
173188
| ^^^^^^^^^^^^^^^ pattern `NonEmptyStruct1` not covered
174189
|
175190
note: `NonEmptyStruct1` defined here
176-
--> $DIR/empty-match.rs:14:8
191+
--> $DIR/empty-match.rs:15:8
177192
|
178193
LL | struct NonEmptyStruct1;
179194
| ^^^^^^^^^^^^^^^
@@ -185,13 +200,13 @@ LL + NonEmptyStruct1 => todo!()
185200
|
186201

187202
error[E0004]: non-exhaustive patterns: `NonEmptyStruct2(_)` not covered
188-
--> $DIR/empty-match.rs:89:24
203+
--> $DIR/empty-match.rs:137:24
189204
|
190205
LL | match_guarded_arm!(NonEmptyStruct2(true));
191206
| ^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyStruct2(_)` not covered
192207
|
193208
note: `NonEmptyStruct2` defined here
194-
--> $DIR/empty-match.rs:15:8
209+
--> $DIR/empty-match.rs:18:8
195210
|
196211
LL | struct NonEmptyStruct2(bool);
197212
| ^^^^^^^^^^^^^^^
@@ -203,13 +218,13 @@ LL + NonEmptyStruct2(_) => todo!()
203218
|
204219

205220
error[E0004]: non-exhaustive patterns: `NonEmptyUnion1 { .. }` not covered
206-
--> $DIR/empty-match.rs:90:24
221+
--> $DIR/empty-match.rs:141:24
207222
|
208223
LL | match_guarded_arm!((NonEmptyUnion1 { foo: () }));
209224
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyUnion1 { .. }` not covered
210225
|
211226
note: `NonEmptyUnion1` defined here
212-
--> $DIR/empty-match.rs:16:7
227+
--> $DIR/empty-match.rs:21:7
213228
|
214229
LL | union NonEmptyUnion1 {
215230
| ^^^^^^^^^^^^^^
@@ -221,13 +236,13 @@ LL + NonEmptyUnion1 { .. } => todo!()
221236
|
222237

223238
error[E0004]: non-exhaustive patterns: `NonEmptyUnion2 { .. }` not covered
224-
--> $DIR/empty-match.rs:91:24
239+
--> $DIR/empty-match.rs:145:24
225240
|
226241
LL | match_guarded_arm!((NonEmptyUnion2 { foo: () }));
227242
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyUnion2 { .. }` not covered
228243
|
229244
note: `NonEmptyUnion2` defined here
230-
--> $DIR/empty-match.rs:19:7
245+
--> $DIR/empty-match.rs:26:7
231246
|
232247
LL | union NonEmptyUnion2 {
233248
| ^^^^^^^^^^^^^^
@@ -239,13 +254,13 @@ LL + NonEmptyUnion2 { .. } => todo!()
239254
|
240255

241256
error[E0004]: non-exhaustive patterns: `NonEmptyEnum1::Foo(_)` not covered
242-
--> $DIR/empty-match.rs:92:24
257+
--> $DIR/empty-match.rs:149:24
243258
|
244259
LL | match_guarded_arm!(NonEmptyEnum1::Foo(true));
245260
| ^^^^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyEnum1::Foo(_)` not covered
246261
|
247262
note: `NonEmptyEnum1` defined here
248-
--> $DIR/empty-match.rs:24:5
263+
--> $DIR/empty-match.rs:33:5
249264
|
250265
LL | enum NonEmptyEnum1 {
251266
| -------------
@@ -259,18 +274,19 @@ LL + NonEmptyEnum1::Foo(_) => todo!()
259274
|
260275

261276
error[E0004]: non-exhaustive patterns: `NonEmptyEnum2::Foo(_)` and `NonEmptyEnum2::Bar` not covered
262-
--> $DIR/empty-match.rs:93:24
277+
--> $DIR/empty-match.rs:153:24
263278
|
264279
LL | match_guarded_arm!(NonEmptyEnum2::Foo(true));
265280
| ^^^^^^^^^^^^^^^^^^^^^^^^ patterns `NonEmptyEnum2::Foo(_)` and `NonEmptyEnum2::Bar` not covered
266281
|
267282
note: `NonEmptyEnum2` defined here
268-
--> $DIR/empty-match.rs:27:5
283+
--> $DIR/empty-match.rs:40:5
269284
|
270285
LL | enum NonEmptyEnum2 {
271286
| -------------
272287
LL | Foo(bool),
273288
| ^^^ not covered
289+
...
274290
LL | Bar,
275291
| ^^^ not covered
276292
= note: the matched value is of type `NonEmptyEnum2`
@@ -281,13 +297,13 @@ LL + NonEmptyEnum2::Foo(_) | NonEmptyEnum2::Bar => todo!()
281297
|
282298

283299
error[E0004]: non-exhaustive patterns: `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered
284-
--> $DIR/empty-match.rs:94:24
300+
--> $DIR/empty-match.rs:157:24
285301
|
286302
LL | match_guarded_arm!(NonEmptyEnum5::V1);
287303
| ^^^^^^^^^^^^^^^^^ patterns `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered
288304
|
289305
note: `NonEmptyEnum5` defined here
290-
--> $DIR/empty-match.rs:30:6
306+
--> $DIR/empty-match.rs:49:6
291307
|
292308
LL | enum NonEmptyEnum5 {
293309
| ^^^^^^^^^^^^^
@@ -298,6 +314,7 @@ LL ~ _ if false => {},
298314
LL + _ => todo!()
299315
|
300316

301-
error: aborting due to 22 previous errors
317+
error: aborting due to 23 previous errors
302318

303-
For more information about this error, try `rustc --explain E0004`.
319+
Some errors have detailed explanations: E0004, E0005.
320+
For more information about an error, try `rustc --explain E0004`.

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

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,49 @@
66
#![feature(never_type_fallback)]
77
#![cfg_attr(exhaustive_patterns, feature(exhaustive_patterns))]
88
#![deny(unreachable_patterns)]
9+
//~^ NOTE the lint level is defined here
910

1011
extern crate empty;
1112

1213
enum EmptyEnum {}
1314

1415
struct NonEmptyStruct1;
16+
//~^ NOTE `NonEmptyStruct1` defined here
17+
//~| NOTE `NonEmptyStruct1` defined here
1518
struct NonEmptyStruct2(bool);
19+
//~^ NOTE `NonEmptyStruct2` defined here
20+
//~| NOTE `NonEmptyStruct2` defined here
1621
union NonEmptyUnion1 {
22+
//~^ NOTE `NonEmptyUnion1` defined here
23+
//~| NOTE `NonEmptyUnion1` defined here
1724
foo: (),
1825
}
1926
union NonEmptyUnion2 {
27+
//~^ NOTE `NonEmptyUnion2` defined here
28+
//~| NOTE `NonEmptyUnion2` defined here
2029
foo: (),
2130
bar: (),
2231
}
2332
enum NonEmptyEnum1 {
2433
Foo(bool),
34+
//~^ NOTE `NonEmptyEnum1` defined here
35+
//~| NOTE `NonEmptyEnum1` defined here
36+
//~| NOTE not covered
37+
//~| NOTE not covered
2538
}
2639
enum NonEmptyEnum2 {
2740
Foo(bool),
41+
//~^ NOTE `NonEmptyEnum2` defined here
42+
//~| NOTE `NonEmptyEnum2` defined here
43+
//~| NOTE not covered
44+
//~| NOTE not covered
2845
Bar,
46+
//~^ NOTE not covered
47+
//~| NOTE not covered
2948
}
3049
enum NonEmptyEnum5 {
50+
//~^ NOTE `NonEmptyEnum5` defined here
51+
//~| NOTE `NonEmptyEnum5` defined here
3152
V1, V2, V3, V4, V5,
3253
}
3354

@@ -51,6 +72,16 @@ fn empty_foreign_enum(x: empty::EmptyForeignEnum) {
5172
}
5273
}
5374

75+
fn empty_foreign_enum_private(x: Option<empty::SecretlyUninhabitedForeignStruct>) {
76+
let None = x;
77+
//~^ ERROR refutable pattern in local binding
78+
//~| NOTE `let` bindings require an "irrefutable pattern"
79+
//~| NOTE for more information, visit
80+
//~| NOTE the matched value is of type
81+
//~| NOTE pattern `Some(_)` not covered
82+
//[exhaustive_patterns]~| NOTE currently uninhabited, but this variant contains private fields
83+
}
84+
5485
fn never(x: !) {
5586
match x {} // ok
5687
match x {
@@ -76,20 +107,55 @@ macro_rules! match_guarded_arm {
76107

77108
fn main() {
78109
match_no_arms!(0u8); //~ ERROR type `u8` is non-empty
110+
//~| NOTE the matched value is of type
79111
match_no_arms!(NonEmptyStruct1); //~ ERROR type `NonEmptyStruct1` is non-empty
112+
//~| NOTE the matched value is of type
80113
match_no_arms!(NonEmptyStruct2(true)); //~ ERROR type `NonEmptyStruct2` is non-empty
114+
//~| NOTE the matched value is of type
81115
match_no_arms!((NonEmptyUnion1 { foo: () })); //~ ERROR type `NonEmptyUnion1` is non-empty
116+
//~| NOTE the matched value is of type
82117
match_no_arms!((NonEmptyUnion2 { foo: () })); //~ ERROR type `NonEmptyUnion2` is non-empty
118+
//~| NOTE the matched value is of type
83119
match_no_arms!(NonEmptyEnum1::Foo(true)); //~ ERROR `NonEmptyEnum1::Foo(_)` not covered
120+
//~| NOTE pattern `NonEmptyEnum1::Foo(_)` not covered
121+
//~| NOTE the matched value is of type
84122
match_no_arms!(NonEmptyEnum2::Foo(true)); //~ ERROR `NonEmptyEnum2::Foo(_)` and `NonEmptyEnum2::Bar` not covered
123+
//~| NOTE patterns `NonEmptyEnum2::Foo(_)` and
124+
//~| NOTE the matched value is of type
85125
match_no_arms!(NonEmptyEnum5::V1); //~ ERROR `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered
126+
//~| NOTE patterns `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`
127+
//~| NOTE the matched value is of type
86128

87129
match_guarded_arm!(0u8); //~ ERROR `_` not covered
130+
//~| NOTE the matched value is of type
131+
//~| NOTE pattern `_` not covered
132+
//~| NOTE in this expansion of match_guarded_arm!
88133
match_guarded_arm!(NonEmptyStruct1); //~ ERROR `NonEmptyStruct1` not covered
134+
//~| NOTE pattern `NonEmptyStruct1` not covered
135+
//~| NOTE the matched value is of type
136+
//~| NOTE in this expansion of match_guarded_arm!
89137
match_guarded_arm!(NonEmptyStruct2(true)); //~ ERROR `NonEmptyStruct2(_)` not covered
138+
//~| NOTE the matched value is of type
139+
//~| NOTE pattern `NonEmptyStruct2(_)` not covered
140+
//~| NOTE in this expansion of match_guarded_arm!
90141
match_guarded_arm!((NonEmptyUnion1 { foo: () })); //~ ERROR `NonEmptyUnion1 { .. }` not covered
142+
//~| NOTE the matched value is of type
143+
//~| NOTE pattern `NonEmptyUnion1 { .. }` not covered
144+
//~| NOTE in this expansion of match_guarded_arm!
91145
match_guarded_arm!((NonEmptyUnion2 { foo: () })); //~ ERROR `NonEmptyUnion2 { .. }` not covered
146+
//~| NOTE the matched value is of type
147+
//~| NOTE pattern `NonEmptyUnion2 { .. }` not covered
148+
//~| NOTE in this expansion of match_guarded_arm!
92149
match_guarded_arm!(NonEmptyEnum1::Foo(true)); //~ ERROR `NonEmptyEnum1::Foo(_)` not covered
150+
//~| NOTE the matched value is of type
151+
//~| NOTE pattern `NonEmptyEnum1::Foo(_)` not covered
152+
//~| NOTE in this expansion of match_guarded_arm!
93153
match_guarded_arm!(NonEmptyEnum2::Foo(true)); //~ ERROR `NonEmptyEnum2::Foo(_)` and `NonEmptyEnum2::Bar` not covered
154+
//~| NOTE the matched value is of type
155+
//~| NOTE patterns `NonEmptyEnum2::Foo(_)` and
156+
//~| NOTE in this expansion of match_guarded_arm!
94157
match_guarded_arm!(NonEmptyEnum5::V1); //~ ERROR `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered
158+
//~| NOTE the matched value is of type
159+
//~| NOTE patterns `NonEmptyEnum5::V1`,
160+
//~| NOTE in this expansion of match_guarded_arm!
95161
}

0 commit comments

Comments
 (0)
Please sign in to comment.