diff --git a/compiler/rustc_pattern_analysis/src/usefulness.rs b/compiler/rustc_pattern_analysis/src/usefulness.rs index 576005b2c7f8f..80a807b4f2759 100644 --- a/compiler/rustc_pattern_analysis/src/usefulness.rs +++ b/compiler/rustc_pattern_analysis/src/usefulness.rs @@ -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()`. diff --git a/tests/ui/pattern/usefulness/empty-match-check-notes.exhaustive_patterns.stderr b/tests/ui/pattern/usefulness/empty-match-check-notes.exhaustive_patterns.stderr index 304435cb21e8a..4c43419243190 100644 --- a/tests/ui/pattern/usefulness/empty-match-check-notes.exhaustive_patterns.stderr +++ b/tests/ui/pattern/usefulness/empty-match-check-notes.exhaustive_patterns.stderr @@ -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 diff --git a/tests/ui/pattern/usefulness/empty-match-check-notes.normal.stderr b/tests/ui/pattern/usefulness/empty-match-check-notes.normal.stderr index 40494b726f00c..45f715dc7b2dc 100644 --- a/tests/ui/pattern/usefulness/empty-match-check-notes.normal.stderr +++ b/tests/ui/pattern/usefulness/empty-match-check-notes.normal.stderr @@ -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 diff --git a/tests/ui/pattern/usefulness/empty-match-check-notes.rs b/tests/ui/pattern/usefulness/empty-match-check-notes.rs index ee9ff3dcf9012..c30cdfc2e4fee 100644 --- a/tests/ui/pattern/usefulness/empty-match-check-notes.rs +++ b/tests/ui/pattern/usefulness/empty-match-check-notes.rs @@ -43,10 +43,10 @@ fn empty_foreign_enum_private(x: Option 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 => {} } } diff --git a/tests/ui/pattern/usefulness/empty-match.exhaustive_patterns.stderr b/tests/ui/pattern/usefulness/empty-match.exhaustive_patterns.stderr index bf758999661e6..5f895fab0fba4 100644 --- a/tests/ui/pattern/usefulness/empty-match.exhaustive_patterns.stderr +++ b/tests/ui/pattern/usefulness/empty-match.exhaustive_patterns.stderr @@ -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 diff --git a/tests/ui/pattern/usefulness/empty-match.normal.stderr b/tests/ui/pattern/usefulness/empty-match.normal.stderr index bf758999661e6..5f895fab0fba4 100644 --- a/tests/ui/pattern/usefulness/empty-match.normal.stderr +++ b/tests/ui/pattern/usefulness/empty-match.normal.stderr @@ -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 diff --git a/tests/ui/pattern/usefulness/empty-match.rs b/tests/ui/pattern/usefulness/empty-match.rs index ff9e488ceaf77..20ab702c9c899 100644 --- a/tests/ui/pattern/usefulness/empty-match.rs +++ b/tests/ui/pattern/usefulness/empty-match.rs @@ -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