diff --git a/src/librustc_mir/hair/pattern/check_match.rs b/src/librustc_mir/hair/pattern/check_match.rs index e886c4ea443e6..984c0c412166d 100644 --- a/src/librustc_mir/hair/pattern/check_match.rs +++ b/src/librustc_mir/hair/pattern/check_match.rs @@ -176,7 +176,7 @@ impl<'tcx> MatchVisitor<'_, 'tcx> { } else { match pat_ty.kind { ty::Never => true, - ty::Adt(def, _) => { + ty::Adt(def, _) if def.is_enum() => { def.variants.is_empty() && !cx.is_foreign_non_exhaustive_enum(pat_ty) } _ => false, @@ -185,7 +185,7 @@ impl<'tcx> MatchVisitor<'_, 'tcx> { if !scrutinee_is_visibly_uninhabited { // We know the type is inhabited, so this must be wrong let (def_span, missing_variants) = match pat_ty.kind { - ty::Adt(def, _) => ( + ty::Adt(def, _) if def.is_enum() => ( self.tcx.hir().span_if_local(def.did), def.variants.iter().map(|variant| variant.ident).collect(), ), diff --git a/src/test/ui/pattern/usefulness/always-inhabited-union-ref.rs b/src/test/ui/pattern/usefulness/always-inhabited-union-ref.rs index b568057ed1e54..11eae2af9c95f 100644 --- a/src/test/ui/pattern/usefulness/always-inhabited-union-ref.rs +++ b/src/test/ui/pattern/usefulness/always-inhabited-union-ref.rs @@ -25,7 +25,7 @@ fn match_on_uninhab() { } match uninhab_union() { - //~^ ERROR non-exhaustive patterns: pattern `Foo` of type `Foo` is not handled + //~^ ERROR non-exhaustive patterns: type `Foo` is non-empty } } diff --git a/src/test/ui/pattern/usefulness/always-inhabited-union-ref.stderr b/src/test/ui/pattern/usefulness/always-inhabited-union-ref.stderr index acf926e9a8323..792ab6f59a439 100644 --- a/src/test/ui/pattern/usefulness/always-inhabited-union-ref.stderr +++ b/src/test/ui/pattern/usefulness/always-inhabited-union-ref.stderr @@ -6,19 +6,11 @@ LL | match uninhab_ref() { | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms -error[E0004]: non-exhaustive patterns: pattern `Foo` of type `Foo` is not handled +error[E0004]: non-exhaustive patterns: type `Foo` is non-empty --> $DIR/always-inhabited-union-ref.rs:27:11 | -LL | pub union Foo { - | - --- variant not covered - | _| - | | -LL | | foo: !, -LL | | } - | |_- `Foo` defined here -... -LL | match uninhab_union() { - | ^^^^^^^^^^^^^^^ +LL | match uninhab_union() { + | ^^^^^^^^^^^^^^^ | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms diff --git a/src/test/ui/pattern/usefulness/match-empty-exhaustive_patterns.rs b/src/test/ui/pattern/usefulness/match-empty-exhaustive_patterns.rs index 61072735e18f0..b55673a1322d3 100644 --- a/src/test/ui/pattern/usefulness/match-empty-exhaustive_patterns.rs +++ b/src/test/ui/pattern/usefulness/match-empty-exhaustive_patterns.rs @@ -3,7 +3,7 @@ #![deny(unreachable_patterns)] enum Foo {} -struct NonEmptyStruct(bool); //~ `NonEmptyStruct` defined here +struct NonEmptyStruct(bool); union NonEmptyUnion1 { foo: (), } @@ -42,11 +42,11 @@ fn main() { match 0u8 {} //~^ ERROR type `u8` is non-empty match NonEmptyStruct(true) {} - //~^ ERROR pattern `NonEmptyStruct` of type `NonEmptyStruct` is not handled + //~^ ERROR type `NonEmptyStruct` is non-empty match (NonEmptyUnion1 { foo: () }) {} - //~^ ERROR pattern `NonEmptyUnion1` of type `NonEmptyUnion1` is not handled + //~^ ERROR type `NonEmptyUnion1` is non-empty match (NonEmptyUnion2 { foo: () }) {} - //~^ ERROR pattern `NonEmptyUnion2` of type `NonEmptyUnion2` is not handled + //~^ ERROR type `NonEmptyUnion2` is non-empty match NonEmptyEnum1::Foo(true) {} //~^ ERROR pattern `Foo` of type `NonEmptyEnum1` is not handled match NonEmptyEnum2::Foo(true) {} diff --git a/src/test/ui/pattern/usefulness/match-empty-exhaustive_patterns.stderr b/src/test/ui/pattern/usefulness/match-empty-exhaustive_patterns.stderr index 82be26cfd873c..7b8bb4158e74d 100644 --- a/src/test/ui/pattern/usefulness/match-empty-exhaustive_patterns.stderr +++ b/src/test/ui/pattern/usefulness/match-empty-exhaustive_patterns.stderr @@ -30,50 +30,27 @@ LL | match 0u8 {} | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms -error[E0004]: non-exhaustive patterns: pattern `NonEmptyStruct` of type `NonEmptyStruct` is not handled +error[E0004]: non-exhaustive patterns: type `NonEmptyStruct` is non-empty --> $DIR/match-empty-exhaustive_patterns.rs:44:11 | -LL | struct NonEmptyStruct(bool); - | ---------------------------- - | | | - | | variant not covered - | `NonEmptyStruct` defined here -... LL | match NonEmptyStruct(true) {} | ^^^^^^^^^^^^^^^^^^^^ | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms -error[E0004]: non-exhaustive patterns: pattern `NonEmptyUnion1` of type `NonEmptyUnion1` is not handled +error[E0004]: non-exhaustive patterns: type `NonEmptyUnion1` is non-empty --> $DIR/match-empty-exhaustive_patterns.rs:46:11 | -LL | union NonEmptyUnion1 { - | - -------------- variant not covered - | _| - | | -LL | | foo: (), -LL | | } - | |_- `NonEmptyUnion1` defined here -... -LL | match (NonEmptyUnion1 { foo: () }) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | match (NonEmptyUnion1 { foo: () }) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms -error[E0004]: non-exhaustive patterns: pattern `NonEmptyUnion2` of type `NonEmptyUnion2` is not handled +error[E0004]: non-exhaustive patterns: type `NonEmptyUnion2` is non-empty --> $DIR/match-empty-exhaustive_patterns.rs:48:11 | -LL | union NonEmptyUnion2 { - | - -------------- variant not covered - | _| - | | -LL | | foo: (), -LL | | bar: (), -LL | | } - | |_- `NonEmptyUnion2` defined here -... -LL | match (NonEmptyUnion2 { foo: () }) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | match (NonEmptyUnion2 { foo: () }) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms diff --git a/src/test/ui/pattern/usefulness/match-empty.rs b/src/test/ui/pattern/usefulness/match-empty.rs index ebbc1358cdbe4..3adbcb8cbbb9e 100644 --- a/src/test/ui/pattern/usefulness/match-empty.rs +++ b/src/test/ui/pattern/usefulness/match-empty.rs @@ -2,7 +2,7 @@ #![deny(unreachable_patterns)] enum Foo {} -struct NonEmptyStruct(bool); //~ `NonEmptyStruct` defined here +struct NonEmptyStruct(bool); union NonEmptyUnion1 { foo: (), } @@ -45,11 +45,11 @@ fn main() { match 0u8 {} //~^ ERROR type `u8` is non-empty match NonEmptyStruct(true) {} - //~^ ERROR pattern `NonEmptyStruct` of type `NonEmptyStruct` is not handled + //~^ ERROR type `NonEmptyStruct` is non-empty match (NonEmptyUnion1 { foo: () }) {} - //~^ ERROR pattern `NonEmptyUnion1` of type `NonEmptyUnion1` is not handled + //~^ ERROR type `NonEmptyUnion1` is non-empty match (NonEmptyUnion2 { foo: () }) {} - //~^ ERROR pattern `NonEmptyUnion2` of type `NonEmptyUnion2` is not handled + //~^ ERROR type `NonEmptyUnion2` is non-empty match NonEmptyEnum1::Foo(true) {} //~^ ERROR pattern `Foo` of type `NonEmptyEnum1` is not handled match NonEmptyEnum2::Foo(true) {} diff --git a/src/test/ui/pattern/usefulness/match-empty.stderr b/src/test/ui/pattern/usefulness/match-empty.stderr index 4ba1c79b4b2db..7446a8e4aee0e 100644 --- a/src/test/ui/pattern/usefulness/match-empty.stderr +++ b/src/test/ui/pattern/usefulness/match-empty.stderr @@ -6,50 +6,27 @@ LL | match 0u8 {} | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms -error[E0004]: non-exhaustive patterns: pattern `NonEmptyStruct` of type `NonEmptyStruct` is not handled +error[E0004]: non-exhaustive patterns: type `NonEmptyStruct` is non-empty --> $DIR/match-empty.rs:47:11 | -LL | struct NonEmptyStruct(bool); - | ---------------------------- - | | | - | | variant not covered - | `NonEmptyStruct` defined here -... LL | match NonEmptyStruct(true) {} | ^^^^^^^^^^^^^^^^^^^^ | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms -error[E0004]: non-exhaustive patterns: pattern `NonEmptyUnion1` of type `NonEmptyUnion1` is not handled +error[E0004]: non-exhaustive patterns: type `NonEmptyUnion1` is non-empty --> $DIR/match-empty.rs:49:11 | -LL | union NonEmptyUnion1 { - | - -------------- variant not covered - | _| - | | -LL | | foo: (), -LL | | } - | |_- `NonEmptyUnion1` defined here -... -LL | match (NonEmptyUnion1 { foo: () }) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | match (NonEmptyUnion1 { foo: () }) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms -error[E0004]: non-exhaustive patterns: pattern `NonEmptyUnion2` of type `NonEmptyUnion2` is not handled +error[E0004]: non-exhaustive patterns: type `NonEmptyUnion2` is non-empty --> $DIR/match-empty.rs:51:11 | -LL | union NonEmptyUnion2 { - | - -------------- variant not covered - | _| - | | -LL | | foo: (), -LL | | bar: (), -LL | | } - | |_- `NonEmptyUnion2` defined here -... -LL | match (NonEmptyUnion2 { foo: () }) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | match (NonEmptyUnion2 { foo: () }) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms diff --git a/src/test/ui/rfc-2008-non-exhaustive/uninhabited/indirect_match_with_exhaustive_patterns.stderr b/src/test/ui/rfc-2008-non-exhaustive/uninhabited/indirect_match_with_exhaustive_patterns.stderr index 42a99367fa977..2c2e542934177 100644 --- a/src/test/ui/rfc-2008-non-exhaustive/uninhabited/indirect_match_with_exhaustive_patterns.stderr +++ b/src/test/ui/rfc-2008-non-exhaustive/uninhabited/indirect_match_with_exhaustive_patterns.stderr @@ -1,4 +1,4 @@ -error[E0004]: non-exhaustive patterns: pattern `IndirectUninhabitedEnum` of type `uninhabited::IndirectUninhabitedEnum` is not handled +error[E0004]: non-exhaustive patterns: type `uninhabited::IndirectUninhabitedEnum` is non-empty --> $DIR/indirect_match_with_exhaustive_patterns.rs:22:11 | LL | match x {} @@ -6,7 +6,7 @@ LL | match x {} | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms -error[E0004]: non-exhaustive patterns: pattern `IndirectUninhabitedStruct` of type `uninhabited::IndirectUninhabitedStruct` is not handled +error[E0004]: non-exhaustive patterns: type `uninhabited::IndirectUninhabitedStruct` is non-empty --> $DIR/indirect_match_with_exhaustive_patterns.rs:26:11 | LL | match x {} @@ -14,7 +14,7 @@ LL | match x {} | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms -error[E0004]: non-exhaustive patterns: pattern `IndirectUninhabitedTupleStruct` of type `uninhabited::IndirectUninhabitedTupleStruct` is not handled +error[E0004]: non-exhaustive patterns: type `uninhabited::IndirectUninhabitedTupleStruct` is non-empty --> $DIR/indirect_match_with_exhaustive_patterns.rs:30:11 | LL | match x {} @@ -22,7 +22,7 @@ LL | match x {} | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms -error[E0004]: non-exhaustive patterns: pattern `IndirectUninhabitedVariants` of type `uninhabited::IndirectUninhabitedVariants` is not handled +error[E0004]: non-exhaustive patterns: type `uninhabited::IndirectUninhabitedVariants` is non-empty --> $DIR/indirect_match_with_exhaustive_patterns.rs:36:11 | LL | match x {} diff --git a/src/test/ui/rfc-2008-non-exhaustive/uninhabited/match_with_exhaustive_patterns.stderr b/src/test/ui/rfc-2008-non-exhaustive/uninhabited/match_with_exhaustive_patterns.stderr index 113b7db1c6e60..21373bb4ed30f 100644 --- a/src/test/ui/rfc-2008-non-exhaustive/uninhabited/match_with_exhaustive_patterns.stderr +++ b/src/test/ui/rfc-2008-non-exhaustive/uninhabited/match_with_exhaustive_patterns.stderr @@ -6,7 +6,7 @@ LL | match x {} | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms -error[E0004]: non-exhaustive patterns: pattern `UninhabitedStruct` of type `uninhabited::UninhabitedStruct` is not handled +error[E0004]: non-exhaustive patterns: type `uninhabited::UninhabitedStruct` is non-empty --> $DIR/match_with_exhaustive_patterns.rs:25:11 | LL | match x {} @@ -14,7 +14,7 @@ LL | match x {} | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms -error[E0004]: non-exhaustive patterns: pattern `UninhabitedTupleStruct` of type `uninhabited::UninhabitedTupleStruct` is not handled +error[E0004]: non-exhaustive patterns: type `uninhabited::UninhabitedTupleStruct` is non-empty --> $DIR/match_with_exhaustive_patterns.rs:29:11 | LL | match x {}