Skip to content

Commit 9dca6be

Browse files
committed
Prefer "0..MAX not covered" to "_ not covered"
1 parent 970f46c commit 9dca6be

7 files changed

+32
-34
lines changed

compiler/rustc_pattern_analysis/src/usefulness.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -1520,11 +1520,9 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
15201520
split_ctors.push(Constructor::Missing);
15211521
}
15221522

1523-
// Decide what constructors to report.
1524-
let is_integers = matches!(ctors_for_ty, ConstructorSet::Integers { .. });
1525-
let always_report_all = place.is_scrutinee && !is_integers;
1526-
// Whether we should report "Enum::A and Enum::C are missing" or "_ is missing".
1527-
let report_individual_missing_ctors = always_report_all || !all_missing;
1523+
// Whether we should report "Enum::A and Enum::C are missing" or "_ is missing". At the top
1524+
// level we prefer to list all constructors.
1525+
let report_individual_missing_ctors = place.is_scrutinee || !all_missing;
15281526
// Which constructors are considered missing. We ensure that `!missing_ctors.is_empty() =>
15291527
// split_ctors.contains(Missing)`. The converse usually holds except when
15301528
// `!place_validity.is_known_valid()`.

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,18 @@ help: you might want to use `if let` to ignore the variant that isn't matched
4343
LL | if let None = x { todo!() };
4444
| ++ +++++++++++
4545

46-
error[E0004]: non-exhaustive patterns: `_` not covered
46+
error[E0004]: non-exhaustive patterns: `0_u8..=u8::MAX` not covered
4747
--> $DIR/empty-match-check-notes.rs:45:11
4848
|
4949
LL | match 0u8 {
50-
| ^^^ pattern `_` not covered
50+
| ^^^ pattern `0_u8..=u8::MAX` not covered
5151
|
5252
= note: the matched value is of type `u8`
5353
= note: match arms with guards don't count towards exhaustivity
5454
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
5555
|
5656
LL ~ _ if false => {},
57-
LL + _ => todo!()
57+
LL + 0_u8..=u8::MAX => todo!()
5858
|
5959

6060
error: aborting due to 6 previous errors

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,18 @@ help: you might want to use `if let` to ignore the variant that isn't matched
4242
LL | if let None = x { todo!() };
4343
| ++ +++++++++++
4444

45-
error[E0004]: non-exhaustive patterns: `_` not covered
45+
error[E0004]: non-exhaustive patterns: `0_u8..=u8::MAX` not covered
4646
--> $DIR/empty-match-check-notes.rs:45:11
4747
|
4848
LL | match 0u8 {
49-
| ^^^ pattern `_` not covered
49+
| ^^^ pattern `0_u8..=u8::MAX` not covered
5050
|
5151
= note: the matched value is of type `u8`
5252
= note: match arms with guards don't count towards exhaustivity
5353
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
5454
|
5555
LL ~ _ if false => {},
56-
LL + _ => todo!()
56+
LL + 0_u8..=u8::MAX => todo!()
5757
|
5858

5959
error: aborting due to 6 previous errors

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ fn empty_foreign_enum_private(x: Option<empty::SecretlyUninhabitedForeignStruct>
4343

4444
fn main() {
4545
match 0u8 {
46-
//~^ ERROR `_` not covered
46+
//~^ ERROR not covered
4747
//~| NOTE the matched value is of type
4848
//~| NOTE match arms with guards don't count towards exhaustivity
49-
//~| NOTE pattern `_` not covered
49+
//~| NOTE not covered
5050
_ if false => {}
5151
}
5252
}

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

+9-9
Original file line numberDiff line numberDiff line change
@@ -148,46 +148,46 @@ 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: `_` not covered
151+
error[E0004]: non-exhaustive patterns: `0_u8..=u8::MAX` not covered
152152
--> $DIR/empty-match.rs:58:24
153153
|
154154
LL | match_guarded_arm!(0u8);
155-
| ^^^ pattern `_` not covered
155+
| ^^^ pattern `0_u8..=u8::MAX` not covered
156156
|
157157
= note: the matched value is of type `u8`
158158
= note: match arms with guards don't count towards exhaustivity
159159
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
160160
|
161161
LL ~ _ if false => {},
162-
LL + _ => todo!()
162+
LL + 0_u8..=u8::MAX => todo!()
163163
|
164164

165-
error[E0004]: non-exhaustive patterns: `_` not covered
165+
error[E0004]: non-exhaustive patterns: `i8::MIN..=i8::MAX` not covered
166166
--> $DIR/empty-match.rs:59:24
167167
|
168168
LL | match_guarded_arm!(0i8);
169-
| ^^^ pattern `_` not covered
169+
| ^^^ pattern `i8::MIN..=i8::MAX` not covered
170170
|
171171
= note: the matched value is of type `i8`
172172
= note: match arms with guards don't count towards exhaustivity
173173
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
174174
|
175175
LL ~ _ if false => {},
176-
LL + _ => todo!()
176+
LL + i8::MIN..=i8::MAX => todo!()
177177
|
178178

179-
error[E0004]: non-exhaustive patterns: `_` not covered
179+
error[E0004]: non-exhaustive patterns: `0_usize..` not covered
180180
--> $DIR/empty-match.rs:60:24
181181
|
182182
LL | match_guarded_arm!(0usize);
183-
| ^^^^^^ pattern `_` not covered
183+
| ^^^^^^ pattern `0_usize..` not covered
184184
|
185185
= note: the matched value is of type `usize`
186186
= note: match arms with guards don't count towards exhaustivity
187187
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
188188
|
189189
LL ~ _ if false => {},
190-
LL + _ => todo!()
190+
LL + 0_usize.. => todo!()
191191
|
192192

193193
error[E0004]: non-exhaustive patterns: `_` not covered

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

+9-9
Original file line numberDiff line numberDiff line change
@@ -148,46 +148,46 @@ 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: `_` not covered
151+
error[E0004]: non-exhaustive patterns: `0_u8..=u8::MAX` not covered
152152
--> $DIR/empty-match.rs:58:24
153153
|
154154
LL | match_guarded_arm!(0u8);
155-
| ^^^ pattern `_` not covered
155+
| ^^^ pattern `0_u8..=u8::MAX` not covered
156156
|
157157
= note: the matched value is of type `u8`
158158
= note: match arms with guards don't count towards exhaustivity
159159
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
160160
|
161161
LL ~ _ if false => {},
162-
LL + _ => todo!()
162+
LL + 0_u8..=u8::MAX => todo!()
163163
|
164164

165-
error[E0004]: non-exhaustive patterns: `_` not covered
165+
error[E0004]: non-exhaustive patterns: `i8::MIN..=i8::MAX` not covered
166166
--> $DIR/empty-match.rs:59:24
167167
|
168168
LL | match_guarded_arm!(0i8);
169-
| ^^^ pattern `_` not covered
169+
| ^^^ pattern `i8::MIN..=i8::MAX` not covered
170170
|
171171
= note: the matched value is of type `i8`
172172
= note: match arms with guards don't count towards exhaustivity
173173
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
174174
|
175175
LL ~ _ if false => {},
176-
LL + _ => todo!()
176+
LL + i8::MIN..=i8::MAX => todo!()
177177
|
178178

179-
error[E0004]: non-exhaustive patterns: `_` not covered
179+
error[E0004]: non-exhaustive patterns: `0_usize..` not covered
180180
--> $DIR/empty-match.rs:60:24
181181
|
182182
LL | match_guarded_arm!(0usize);
183-
| ^^^^^^ pattern `_` not covered
183+
| ^^^^^^ pattern `0_usize..` not covered
184184
|
185185
= note: the matched value is of type `usize`
186186
= note: match arms with guards don't count towards exhaustivity
187187
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
188188
|
189189
LL ~ _ if false => {},
190-
LL + _ => todo!()
190+
LL + 0_usize.. => todo!()
191191
|
192192

193193
error[E0004]: non-exhaustive patterns: `_` not covered

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ fn nonempty() {
5555
match_no_arms!(NonEmptyEnum2::Foo(true)); //~ ERROR `NonEmptyEnum2::Foo(_)` and `NonEmptyEnum2::Bar` not covered
5656
match_no_arms!(NonEmptyEnum5::V1); //~ ERROR `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered
5757

58-
match_guarded_arm!(0u8); //~ ERROR `_` not covered
59-
match_guarded_arm!(0i8); //~ ERROR `_` not covered
60-
match_guarded_arm!(0usize); //~ ERROR `_` not covered
58+
match_guarded_arm!(0u8); //~ ERROR `0_u8..=u8::MAX` not covered
59+
match_guarded_arm!(0i8); //~ ERROR `i8::MIN..=i8::MAX` not covered
60+
match_guarded_arm!(0usize); //~ ERROR `0_usize..` not covered
6161
match_guarded_arm!(0isize); //~ ERROR `_` not covered
6262
match_guarded_arm!(NonEmptyStruct1); //~ ERROR `NonEmptyStruct1` not covered
6363
match_guarded_arm!(NonEmptyStruct2(true)); //~ ERROR `NonEmptyStruct2(_)` not covered

0 commit comments

Comments
 (0)