Skip to content

Commit b5f0f44

Browse files
committed
Tweak diagnostic for consistency
1 parent acefba3 commit b5f0f44

File tree

6 files changed

+107
-61
lines changed

6 files changed

+107
-61
lines changed

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,10 +1018,8 @@ fn adt_defined_here<'p, 'tcx>(
10181018
let ty = ty.peel_refs();
10191019
if let ty::Adt(def, _) = ty.kind() {
10201020
let mut spans = vec![];
1021-
if witnesses.len() < 5 {
1022-
for sp in maybe_point_at_variant(cx, *def, witnesses.iter()) {
1023-
spans.push(sp);
1024-
}
1021+
for sp in maybe_point_at_variant(cx, *def, witnesses.iter().take(5)) {
1022+
spans.push(sp);
10251023
}
10261024
let def_span = cx
10271025
.tcx

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

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

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

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

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

3131
error[E0005]: refutable pattern in local binding
32-
--> $DIR/empty-match.rs:76:9
32+
--> $DIR/empty-match.rs:86:9
3333
|
3434
LL | let None = x;
3535
| ^^^^ pattern `Some(_)` not covered
@@ -44,19 +44,19 @@ LL | if let None = x { todo!() };
4444
| ++ +++++++++++
4545

4646
error: unreachable pattern
47-
--> $DIR/empty-match.rs:88:9
47+
--> $DIR/empty-match.rs:98:9
4848
|
4949
LL | _ => {},
5050
| ^
5151

5252
error: unreachable pattern
53-
--> $DIR/empty-match.rs:91:9
53+
--> $DIR/empty-match.rs:101:9
5454
|
5555
LL | _ if false => {},
5656
| ^
5757

5858
error[E0004]: non-exhaustive patterns: type `u8` is non-empty
59-
--> $DIR/empty-match.rs:109:20
59+
--> $DIR/empty-match.rs:119:20
6060
|
6161
LL | match_no_arms!(0u8);
6262
| ^^^
@@ -65,7 +65,7 @@ LL | match_no_arms!(0u8);
6565
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern
6666

6767
error[E0004]: non-exhaustive patterns: type `NonEmptyStruct1` is non-empty
68-
--> $DIR/empty-match.rs:111:20
68+
--> $DIR/empty-match.rs:121:20
6969
|
7070
LL | match_no_arms!(NonEmptyStruct1);
7171
| ^^^^^^^^^^^^^^^
@@ -79,7 +79,7 @@ LL | struct NonEmptyStruct1;
7979
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern
8080

8181
error[E0004]: non-exhaustive patterns: type `NonEmptyStruct2` is non-empty
82-
--> $DIR/empty-match.rs:113:20
82+
--> $DIR/empty-match.rs:123:20
8383
|
8484
LL | match_no_arms!(NonEmptyStruct2(true));
8585
| ^^^^^^^^^^^^^^^^^^^^^
@@ -93,7 +93,7 @@ LL | struct NonEmptyStruct2(bool);
9393
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern
9494

9595
error[E0004]: non-exhaustive patterns: type `NonEmptyUnion1` is non-empty
96-
--> $DIR/empty-match.rs:115:20
96+
--> $DIR/empty-match.rs:125:20
9797
|
9898
LL | match_no_arms!((NonEmptyUnion1 { foo: () }));
9999
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -107,7 +107,7 @@ LL | union NonEmptyUnion1 {
107107
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern
108108

109109
error[E0004]: non-exhaustive patterns: type `NonEmptyUnion2` is non-empty
110-
--> $DIR/empty-match.rs:117:20
110+
--> $DIR/empty-match.rs:127:20
111111
|
112112
LL | match_no_arms!((NonEmptyUnion2 { foo: () }));
113113
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -121,7 +121,7 @@ LL | union NonEmptyUnion2 {
121121
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern
122122

123123
error[E0004]: non-exhaustive patterns: `NonEmptyEnum1::Foo(_)` not covered
124-
--> $DIR/empty-match.rs:119:20
124+
--> $DIR/empty-match.rs:129:20
125125
|
126126
LL | match_no_arms!(NonEmptyEnum1::Foo(true));
127127
| ^^^^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyEnum1::Foo(_)` not covered
@@ -137,7 +137,7 @@ LL | Foo(bool),
137137
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern
138138

139139
error[E0004]: non-exhaustive patterns: `NonEmptyEnum2::Foo(_)` and `NonEmptyEnum2::Bar` not covered
140-
--> $DIR/empty-match.rs:122:20
140+
--> $DIR/empty-match.rs:132:20
141141
|
142142
LL | match_no_arms!(NonEmptyEnum2::Foo(true));
143143
| ^^^^^^^^^^^^^^^^^^^^^^^^ patterns `NonEmptyEnum2::Foo(_)` and `NonEmptyEnum2::Bar` not covered
@@ -156,21 +156,28 @@ LL | Bar,
156156
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or multiple match arms
157157

158158
error[E0004]: non-exhaustive patterns: `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered
159-
--> $DIR/empty-match.rs:125:20
159+
--> $DIR/empty-match.rs:135:20
160160
|
161161
LL | match_no_arms!(NonEmptyEnum5::V1);
162162
| ^^^^^^^^^^^^^^^^^ patterns `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered
163163
|
164164
note: `NonEmptyEnum5` defined here
165-
--> $DIR/empty-match.rs:49:6
165+
--> $DIR/empty-match.rs:50:5
166166
|
167167
LL | enum NonEmptyEnum5 {
168-
| ^^^^^^^^^^^^^
168+
| -------------
169+
LL | V1, V2, V3, V4, V5,
170+
| ^^ ^^ ^^ ^^ ^^ not covered
171+
| | | | |
172+
| | | | not covered
173+
| | | not covered
174+
| | not covered
175+
| not covered
169176
= note: the matched value is of type `NonEmptyEnum5`
170177
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or multiple match arms
171178

172179
error[E0004]: non-exhaustive patterns: `_` not covered
173-
--> $DIR/empty-match.rs:129:24
180+
--> $DIR/empty-match.rs:139:24
174181
|
175182
LL | match_guarded_arm!(0u8);
176183
| ^^^ pattern `_` not covered
@@ -184,7 +191,7 @@ LL + _ => todo!()
184191
|
185192

186193
error[E0004]: non-exhaustive patterns: `NonEmptyStruct1` not covered
187-
--> $DIR/empty-match.rs:134:24
194+
--> $DIR/empty-match.rs:144:24
188195
|
189196
LL | match_guarded_arm!(NonEmptyStruct1);
190197
| ^^^^^^^^^^^^^^^ pattern `NonEmptyStruct1` not covered
@@ -203,7 +210,7 @@ LL + NonEmptyStruct1 => todo!()
203210
|
204211

205212
error[E0004]: non-exhaustive patterns: `NonEmptyStruct2(_)` not covered
206-
--> $DIR/empty-match.rs:139:24
213+
--> $DIR/empty-match.rs:149:24
207214
|
208215
LL | match_guarded_arm!(NonEmptyStruct2(true));
209216
| ^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyStruct2(_)` not covered
@@ -222,7 +229,7 @@ LL + NonEmptyStruct2(_) => todo!()
222229
|
223230

224231
error[E0004]: non-exhaustive patterns: `NonEmptyUnion1 { .. }` not covered
225-
--> $DIR/empty-match.rs:144:24
232+
--> $DIR/empty-match.rs:154:24
226233
|
227234
LL | match_guarded_arm!((NonEmptyUnion1 { foo: () }));
228235
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyUnion1 { .. }` not covered
@@ -241,7 +248,7 @@ LL + NonEmptyUnion1 { .. } => todo!()
241248
|
242249

243250
error[E0004]: non-exhaustive patterns: `NonEmptyUnion2 { .. }` not covered
244-
--> $DIR/empty-match.rs:149:24
251+
--> $DIR/empty-match.rs:159:24
245252
|
246253
LL | match_guarded_arm!((NonEmptyUnion2 { foo: () }));
247254
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyUnion2 { .. }` not covered
@@ -260,7 +267,7 @@ LL + NonEmptyUnion2 { .. } => todo!()
260267
|
261268

262269
error[E0004]: non-exhaustive patterns: `NonEmptyEnum1::Foo(_)` not covered
263-
--> $DIR/empty-match.rs:154:24
270+
--> $DIR/empty-match.rs:164:24
264271
|
265272
LL | match_guarded_arm!(NonEmptyEnum1::Foo(true));
266273
| ^^^^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyEnum1::Foo(_)` not covered
@@ -281,7 +288,7 @@ LL + NonEmptyEnum1::Foo(_) => todo!()
281288
|
282289

283290
error[E0004]: non-exhaustive patterns: `NonEmptyEnum2::Foo(_)` and `NonEmptyEnum2::Bar` not covered
284-
--> $DIR/empty-match.rs:159:24
291+
--> $DIR/empty-match.rs:169:24
285292
|
286293
LL | match_guarded_arm!(NonEmptyEnum2::Foo(true));
287294
| ^^^^^^^^^^^^^^^^^^^^^^^^ patterns `NonEmptyEnum2::Foo(_)` and `NonEmptyEnum2::Bar` not covered
@@ -305,16 +312,23 @@ LL + NonEmptyEnum2::Foo(_) | NonEmptyEnum2::Bar => todo!()
305312
|
306313

307314
error[E0004]: non-exhaustive patterns: `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered
308-
--> $DIR/empty-match.rs:164:24
315+
--> $DIR/empty-match.rs:174:24
309316
|
310317
LL | match_guarded_arm!(NonEmptyEnum5::V1);
311318
| ^^^^^^^^^^^^^^^^^ patterns `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered
312319
|
313320
note: `NonEmptyEnum5` defined here
314-
--> $DIR/empty-match.rs:49:6
321+
--> $DIR/empty-match.rs:50:5
315322
|
316323
LL | enum NonEmptyEnum5 {
317-
| ^^^^^^^^^^^^^
324+
| -------------
325+
LL | V1, V2, V3, V4, V5,
326+
| ^^ ^^ ^^ ^^ ^^ not covered
327+
| | | | |
328+
| | | | not covered
329+
| | | not covered
330+
| | not covered
331+
| not covered
318332
= note: the matched value is of type `NonEmptyEnum5`
319333
= note: match arms with guards don't count towards exhaustivity
320334
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown, or multiple match arms

0 commit comments

Comments
 (0)