Skip to content

Commit dd74ae0

Browse files
authored
Rollup merge of rust-lang#111951 - cjgillot:uninh-comment, r=Nadrieril
Correct comment on privately uninhabited pattern. Follow-up to rust-lang#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

+2-2
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

+56-38
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`.

0 commit comments

Comments
 (0)