Skip to content

Commit

Permalink
Prefer "0..MAX not covered" to "_ not covered"
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadrieril committed Feb 7, 2024
1 parent 970f46c commit 9dca6be
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 34 deletions.
8 changes: 3 additions & 5 deletions compiler/rustc_pattern_analysis/src/usefulness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1520,11 +1520,9 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
split_ctors.push(Constructor::Missing);
}

// Decide what constructors to report.
let is_integers = matches!(ctors_for_ty, ConstructorSet::Integers { .. });
let always_report_all = place.is_scrutinee && !is_integers;
// Whether we should report "Enum::A and Enum::C are missing" or "_ is missing".
let report_individual_missing_ctors = always_report_all || !all_missing;
// Whether we should report "Enum::A and Enum::C are missing" or "_ is missing". At the top
// level we prefer to list all constructors.
let report_individual_missing_ctors = place.is_scrutinee || !all_missing;
// Which constructors are considered missing. We ensure that `!missing_ctors.is_empty() =>
// split_ctors.contains(Missing)`. The converse usually holds except when
// `!place_validity.is_known_valid()`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,18 @@ help: you might want to use `if let` to ignore the variant that isn't matched
LL | if let None = x { todo!() };
| ++ +++++++++++

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

error: aborting due to 6 previous errors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ help: you might want to use `if let` to ignore the variant that isn't matched
LL | if let None = x { todo!() };
| ++ +++++++++++

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

error: aborting due to 6 previous errors
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/pattern/usefulness/empty-match-check-notes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ fn empty_foreign_enum_private(x: Option<empty::SecretlyUninhabitedForeignStruct>

fn main() {
match 0u8 {
//~^ ERROR `_` not covered
//~^ ERROR not covered
//~| NOTE the matched value is of type
//~| NOTE match arms with guards don't count towards exhaustivity
//~| NOTE pattern `_` not covered
//~| NOTE not covered
_ if false => {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,46 +148,46 @@ LL | V5,
= note: the matched value is of type `NonEmptyEnum5`
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or multiple match arms

error[E0004]: non-exhaustive patterns: `_` not covered
error[E0004]: non-exhaustive patterns: `0_u8..=u8::MAX` not covered
--> $DIR/empty-match.rs:58:24
|
LL | match_guarded_arm!(0u8);
| ^^^ pattern `_` not covered
| ^^^ pattern `0_u8..=u8::MAX` not covered
|
= note: the matched value is of type `u8`
= note: match arms with guards don't count towards exhaustivity
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
|
LL ~ _ if false => {},
LL + _ => todo!()
LL + 0_u8..=u8::MAX => todo!()
|

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

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

error[E0004]: non-exhaustive patterns: `_` not covered
Expand Down
18 changes: 9 additions & 9 deletions tests/ui/pattern/usefulness/empty-match.normal.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -148,46 +148,46 @@ LL | V5,
= note: the matched value is of type `NonEmptyEnum5`
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or multiple match arms

error[E0004]: non-exhaustive patterns: `_` not covered
error[E0004]: non-exhaustive patterns: `0_u8..=u8::MAX` not covered
--> $DIR/empty-match.rs:58:24
|
LL | match_guarded_arm!(0u8);
| ^^^ pattern `_` not covered
| ^^^ pattern `0_u8..=u8::MAX` not covered
|
= note: the matched value is of type `u8`
= note: match arms with guards don't count towards exhaustivity
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
|
LL ~ _ if false => {},
LL + _ => todo!()
LL + 0_u8..=u8::MAX => todo!()
|

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

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

error[E0004]: non-exhaustive patterns: `_` not covered
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/pattern/usefulness/empty-match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ fn nonempty() {
match_no_arms!(NonEmptyEnum2::Foo(true)); //~ ERROR `NonEmptyEnum2::Foo(_)` and `NonEmptyEnum2::Bar` not covered
match_no_arms!(NonEmptyEnum5::V1); //~ ERROR `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered

match_guarded_arm!(0u8); //~ ERROR `_` not covered
match_guarded_arm!(0i8); //~ ERROR `_` not covered
match_guarded_arm!(0usize); //~ ERROR `_` not covered
match_guarded_arm!(0u8); //~ ERROR `0_u8..=u8::MAX` not covered
match_guarded_arm!(0i8); //~ ERROR `i8::MIN..=i8::MAX` not covered
match_guarded_arm!(0usize); //~ ERROR `0_usize..` not covered
match_guarded_arm!(0isize); //~ ERROR `_` not covered
match_guarded_arm!(NonEmptyStruct1); //~ ERROR `NonEmptyStruct1` not covered
match_guarded_arm!(NonEmptyStruct2(true)); //~ ERROR `NonEmptyStruct2(_)` not covered
Expand Down

0 comments on commit 9dca6be

Please sign in to comment.