Skip to content

Commit

Permalink
Unrolled build for rust-lang#120727
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#120727 - Nadrieril:tweak-int-reporting, r=compiler-errors

exhaustiveness: Prefer "`0..MAX` not covered" to "`_` not covered"

There was an exception when reporting integer ranges as missing, it's been there for as long as I can remember. This PR removes it. I think it's nicer to report "`0..MAX` not covered" than "`_` not covered". This also makes it consistent with enums, where we report individual enum variants in this case (as showcased in the rest of the `empty-match.rs` test).

r? ``@estebank``
  • Loading branch information
rust-timer authored Feb 8, 2024
2 parents af88f7d + 9dca6be commit 9ff31ab
Show file tree
Hide file tree
Showing 7 changed files with 192 additions and 50 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 => {}
}
}
105 changes: 87 additions & 18 deletions tests/ui/pattern/usefulness/empty-match.exhaustive_patterns.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,36 @@ LL | match_no_arms!(0u8);
= note: the matched value is of type `u8`
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern

error[E0004]: non-exhaustive patterns: type `NonEmptyStruct1` is non-empty
error[E0004]: non-exhaustive patterns: type `i8` is non-empty
--> $DIR/empty-match.rs:47:20
|
LL | match_no_arms!(0i8);
| ^^^
|
= note: the matched value is of type `i8`
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern

error[E0004]: non-exhaustive patterns: type `usize` is non-empty
--> $DIR/empty-match.rs:48:20
|
LL | match_no_arms!(0usize);
| ^^^^^^
|
= note: the matched value is of type `usize`
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern

error[E0004]: non-exhaustive patterns: type `isize` is non-empty
--> $DIR/empty-match.rs:49:20
|
LL | match_no_arms!(0isize);
| ^^^^^^
|
= note: the matched value is of type `isize`
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern

error[E0004]: non-exhaustive patterns: type `NonEmptyStruct1` is non-empty
--> $DIR/empty-match.rs:50:20
|
LL | match_no_arms!(NonEmptyStruct1);
| ^^^^^^^^^^^^^^^
|
Expand All @@ -22,7 +49,7 @@ LL | struct NonEmptyStruct1;
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern

error[E0004]: non-exhaustive patterns: type `NonEmptyStruct2` is non-empty
--> $DIR/empty-match.rs:48:20
--> $DIR/empty-match.rs:51:20
|
LL | match_no_arms!(NonEmptyStruct2(true));
| ^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -36,7 +63,7 @@ LL | struct NonEmptyStruct2(bool);
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern

error[E0004]: non-exhaustive patterns: type `NonEmptyUnion1` is non-empty
--> $DIR/empty-match.rs:49:20
--> $DIR/empty-match.rs:52:20
|
LL | match_no_arms!((NonEmptyUnion1 { foo: () }));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -50,7 +77,7 @@ LL | union NonEmptyUnion1 {
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern

error[E0004]: non-exhaustive patterns: type `NonEmptyUnion2` is non-empty
--> $DIR/empty-match.rs:50:20
--> $DIR/empty-match.rs:53:20
|
LL | match_no_arms!((NonEmptyUnion2 { foo: () }));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -64,7 +91,7 @@ LL | union NonEmptyUnion2 {
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern

error[E0004]: non-exhaustive patterns: `NonEmptyEnum1::Foo(_)` not covered
--> $DIR/empty-match.rs:51:20
--> $DIR/empty-match.rs:54:20
|
LL | match_no_arms!(NonEmptyEnum1::Foo(true));
| ^^^^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyEnum1::Foo(_)` not covered
Expand All @@ -80,7 +107,7 @@ LL | Foo(bool),
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern

error[E0004]: non-exhaustive patterns: `NonEmptyEnum2::Foo(_)` and `NonEmptyEnum2::Bar` not covered
--> $DIR/empty-match.rs:52:20
--> $DIR/empty-match.rs:55:20
|
LL | match_no_arms!(NonEmptyEnum2::Foo(true));
| ^^^^^^^^^^^^^^^^^^^^^^^^ patterns `NonEmptyEnum2::Foo(_)` and `NonEmptyEnum2::Bar` not covered
Expand All @@ -98,7 +125,7 @@ LL | Bar,
= 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: `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered
--> $DIR/empty-match.rs:53:20
--> $DIR/empty-match.rs:56:20
|
LL | match_no_arms!(NonEmptyEnum5::V1);
| ^^^^^^^^^^^^^^^^^ patterns `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered
Expand All @@ -121,22 +148,64 @@ 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
--> $DIR/empty-match.rs:55:24
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 + 0_u8..=u8::MAX => todo!()
|

error[E0004]: non-exhaustive patterns: `i8::MIN..=i8::MAX` not covered
--> $DIR/empty-match.rs:59:24
|
LL | match_guarded_arm!(0i8);
| ^^^ 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 + i8::MIN..=i8::MAX => todo!()
|

error[E0004]: non-exhaustive patterns: `0_usize..` not covered
--> $DIR/empty-match.rs:60:24
|
LL | match_guarded_arm!(0usize);
| ^^^^^^ 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 + 0_usize.. => todo!()
|

error[E0004]: non-exhaustive patterns: `_` not covered
--> $DIR/empty-match.rs:61:24
|
LL | match_guarded_arm!(0isize);
| ^^^^^^ pattern `_` not covered
|
= note: the matched value is of type `isize`
= 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!()
|

error[E0004]: non-exhaustive patterns: `NonEmptyStruct1` not covered
--> $DIR/empty-match.rs:56:24
--> $DIR/empty-match.rs:62:24
|
LL | match_guarded_arm!(NonEmptyStruct1);
| ^^^^^^^^^^^^^^^ pattern `NonEmptyStruct1` not covered
Expand All @@ -155,7 +224,7 @@ LL + NonEmptyStruct1 => todo!()
|

error[E0004]: non-exhaustive patterns: `NonEmptyStruct2(_)` not covered
--> $DIR/empty-match.rs:57:24
--> $DIR/empty-match.rs:63:24
|
LL | match_guarded_arm!(NonEmptyStruct2(true));
| ^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyStruct2(_)` not covered
Expand All @@ -174,7 +243,7 @@ LL + NonEmptyStruct2(_) => todo!()
|

error[E0004]: non-exhaustive patterns: `NonEmptyUnion1 { .. }` not covered
--> $DIR/empty-match.rs:58:24
--> $DIR/empty-match.rs:64:24
|
LL | match_guarded_arm!((NonEmptyUnion1 { foo: () }));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyUnion1 { .. }` not covered
Expand All @@ -193,7 +262,7 @@ LL + NonEmptyUnion1 { .. } => todo!()
|

error[E0004]: non-exhaustive patterns: `NonEmptyUnion2 { .. }` not covered
--> $DIR/empty-match.rs:59:24
--> $DIR/empty-match.rs:65:24
|
LL | match_guarded_arm!((NonEmptyUnion2 { foo: () }));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyUnion2 { .. }` not covered
Expand All @@ -212,7 +281,7 @@ LL + NonEmptyUnion2 { .. } => todo!()
|

error[E0004]: non-exhaustive patterns: `NonEmptyEnum1::Foo(_)` not covered
--> $DIR/empty-match.rs:60:24
--> $DIR/empty-match.rs:66:24
|
LL | match_guarded_arm!(NonEmptyEnum1::Foo(true));
| ^^^^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyEnum1::Foo(_)` not covered
Expand All @@ -233,7 +302,7 @@ LL + NonEmptyEnum1::Foo(_) => todo!()
|

error[E0004]: non-exhaustive patterns: `NonEmptyEnum2::Foo(_)` and `NonEmptyEnum2::Bar` not covered
--> $DIR/empty-match.rs:61:24
--> $DIR/empty-match.rs:67:24
|
LL | match_guarded_arm!(NonEmptyEnum2::Foo(true));
| ^^^^^^^^^^^^^^^^^^^^^^^^ patterns `NonEmptyEnum2::Foo(_)` and `NonEmptyEnum2::Bar` not covered
Expand All @@ -256,7 +325,7 @@ LL + NonEmptyEnum2::Foo(_) | NonEmptyEnum2::Bar => todo!()
|

error[E0004]: non-exhaustive patterns: `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered
--> $DIR/empty-match.rs:62:24
--> $DIR/empty-match.rs:68:24
|
LL | match_guarded_arm!(NonEmptyEnum5::V1);
| ^^^^^^^^^^^^^^^^^ patterns `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered
Expand Down Expand Up @@ -284,6 +353,6 @@ LL ~ _ if false => {},
LL + _ => todo!()
|

error: aborting due to 16 previous errors
error: aborting due to 22 previous errors

For more information about this error, try `rustc --explain E0004`.
Loading

0 comments on commit 9ff31ab

Please sign in to comment.