about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNadrieril <nadrieril+git@gmail.com>2019-11-30 15:41:27 +0000
committerNadrieril <nadrieril+git@gmail.com>2019-12-04 16:43:21 +0000
commit063d74f5d9b4a08b103137405baa076c55df9eae (patch)
treef1d25c9bc73e5c6d1b9070ba227ec986bb6fbf05
parent86fb2ef2e1ee14741fdb38e15f8d530d863c2628 (diff)
downloadrust-063d74f5d9b4a08b103137405baa076c55df9eae.tar.gz
rust-063d74f5d9b4a08b103137405baa076c55df9eae.zip
Fix explanation of handling of empty enums
-rw-r--r--src/librustc_mir/hair/pattern/_match.rs25
1 files changed, 8 insertions, 17 deletions
diff --git a/src/librustc_mir/hair/pattern/_match.rs b/src/librustc_mir/hair/pattern/_match.rs
index 8ee942e53e0..08fcaf20d2c 100644
--- a/src/librustc_mir/hair/pattern/_match.rs
+++ b/src/librustc_mir/hair/pattern/_match.rs
@@ -1267,23 +1267,14 @@ fn all_constructors<'a, 'tcx>(
             let is_declared_nonexhaustive =
                 def.is_variant_list_non_exhaustive() && !cx.is_local(pcx.ty);
 
-            // If our scrutinee is *privately* an empty enum, we must treat it as though it had
-            // an "unknown" constructor (in that case, all other patterns obviously can't be
-            // variants) to avoid exposing its emptyness. See the `match_privately_empty` test
-            // for details.
-            let is_privately_empty = if cx.tcx.features().exhaustive_patterns {
-                // This cannot happen because we have already filtered out uninhabited variants.
-                false
-            } else {
-                // FIXME: this is fishy
-                def.variants.is_empty()
-            };
-
-            if is_privately_empty || is_declared_nonexhaustive {
-                vec![NonExhaustive]
-            } else {
-                ctors
-            }
+            // If `exhaustive_patterns` is disabled and our scrutinee is an empty enum, we treat it
+            // as though it had an "unknown" constructor to avoid exposing its emptyness. Note that
+            // an empty match will still be considered exhaustive because that case is handled
+            // separately in `check_match`.
+            let is_secretly_empty =
+                def.variants.is_empty() && !cx.tcx.features().exhaustive_patterns;
+
+            if is_secretly_empty || is_declared_nonexhaustive { vec![NonExhaustive] } else { ctors }
         }
         ty::Char => {
             vec![