about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNadrieril <nadrieril+git@gmail.com>2019-12-03 14:08:14 +0000
committerNadrieril <nadrieril+git@gmail.com>2019-12-04 16:43:21 +0000
commitc0f3c06c6da71dc1dc84bc7240d1b26c3ee7facb (patch)
tree2f412493aae3a4da9643e3e77d2c0cf1666eabcf
parent2099dd1aa27683240420eeb1ed5ee468a0d36007 (diff)
downloadrust-c0f3c06c6da71dc1dc84bc7240d1b26c3ee7facb.tar.gz
rust-c0f3c06c6da71dc1dc84bc7240d1b26c3ee7facb.zip
Only warn about missing patterns in the case of an enum
-rw-r--r--src/librustc_mir/hair/pattern/check_match.rs4
-rw-r--r--src/test/ui/pattern/usefulness/always-inhabited-union-ref.rs2
-rw-r--r--src/test/ui/pattern/usefulness/always-inhabited-union-ref.stderr14
-rw-r--r--src/test/ui/pattern/usefulness/match-empty-exhaustive_patterns.rs8
-rw-r--r--src/test/ui/pattern/usefulness/match-empty-exhaustive_patterns.stderr37
-rw-r--r--src/test/ui/pattern/usefulness/match-empty.rs8
-rw-r--r--src/test/ui/pattern/usefulness/match-empty.stderr37
-rw-r--r--src/test/ui/rfc-2008-non-exhaustive/uninhabited/indirect_match_with_exhaustive_patterns.stderr8
-rw-r--r--src/test/ui/rfc-2008-non-exhaustive/uninhabited/match_with_exhaustive_patterns.stderr4
9 files changed, 34 insertions, 88 deletions
diff --git a/src/librustc_mir/hair/pattern/check_match.rs b/src/librustc_mir/hair/pattern/check_match.rs
index e886c4ea443..984c0c41216 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 b568057ed1e..11eae2af9c9 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 acf926e9a83..792ab6f59a4 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 61072735e18..b55673a1322 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 82be26cfd87..7b8bb4158e7 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 ebbc1358cdb..3adbcb8cbbb 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 4ba1c79b4b2..7446a8e4aee 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 42a99367fa9..2c2e5429341 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 113b7db1c6e..21373bb4ed3 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 {}