Skip to content

exhaustiveness: Prefer "0..MAX not covered" to "_ not covered" #120727

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions compiler/rustc_pattern_analysis/src/usefulness.rs
Original file line number Diff line number Diff line change
@@ -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()`.
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
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
@@ -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
@@ -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);
| ^^^^^^^^^^^^^^^
|
@@ -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));
| ^^^^^^^^^^^^^^^^^^^^^
@@ -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: () }));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -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: () }));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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`.
105 changes: 87 additions & 18 deletions tests/ui/pattern/usefulness/empty-match.normal.stderr
Original file line number Diff line number Diff line change
@@ -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);
| ^^^^^^^^^^^^^^^
|
@@ -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));
| ^^^^^^^^^^^^^^^^^^^^^
@@ -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: () }));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -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: () }));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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`.
8 changes: 7 additions & 1 deletion tests/ui/pattern/usefulness/empty-match.rs
Original file line number Diff line number Diff line change
@@ -44,6 +44,9 @@ fn nonempty() {
}

match_no_arms!(0u8); //~ ERROR type `u8` is non-empty
match_no_arms!(0i8); //~ ERROR type `i8` is non-empty
match_no_arms!(0usize); //~ ERROR type `usize` is non-empty
match_no_arms!(0isize); //~ ERROR type `isize` is non-empty
match_no_arms!(NonEmptyStruct1); //~ ERROR type `NonEmptyStruct1` is non-empty
match_no_arms!(NonEmptyStruct2(true)); //~ ERROR type `NonEmptyStruct2` is non-empty
match_no_arms!((NonEmptyUnion1 { foo: () })); //~ ERROR type `NonEmptyUnion1` is non-empty
@@ -52,7 +55,10 @@ 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!(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
match_guarded_arm!((NonEmptyUnion1 { foo: () })); //~ ERROR `NonEmptyUnion1 { .. }` not covered