about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_mir_build/src/thir/pattern/check_match.rs12
-rw-r--r--compiler/rustc_mir_build/src/thir/pattern/usefulness.rs19
2 files changed, 22 insertions, 9 deletions
diff --git a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs
index 397706851cb..47456f469f1 100644
--- a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs
+++ b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs
@@ -1,6 +1,6 @@
-use super::usefulness::Usefulness::*;
 use super::usefulness::{
-    compute_match_usefulness, expand_pattern, MatchArm, MatchCheckCtxt, UsefulnessReport,
+    compute_match_usefulness, expand_pattern, MatchArm, MatchCheckCtxt, Reachability,
+    UsefulnessReport,
 };
 use super::{PatCtxt, PatKind, PatternError};
 
@@ -398,10 +398,11 @@ fn report_arm_reachability<'p, 'tcx>(
     report: &UsefulnessReport<'p, 'tcx>,
     source: hir::MatchSource,
 ) {
+    use Reachability::*;
     let mut catchall = None;
     for (arm_index, (arm, is_useful)) in report.arm_usefulness.iter().enumerate() {
         match is_useful {
-            NotUseful => {
+            Unreachable => {
                 match source {
                     hir::MatchSource::WhileDesugar => bug!(),
 
@@ -430,9 +431,9 @@ fn report_arm_reachability<'p, 'tcx>(
                     hir::MatchSource::AwaitDesugar | hir::MatchSource::TryDesugar => {}
                 }
             }
-            Useful(unreachables) if unreachables.is_empty() => {}
+            Reachable(unreachables) if unreachables.is_empty() => {}
             // The arm is reachable, but contains unreachable subpatterns (from or-patterns).
-            Useful(unreachables) => {
+            Reachable(unreachables) => {
                 let mut unreachables: Vec<_> = unreachables.iter().collect();
                 // Emit lints in the order in which they occur in the file.
                 unreachables.sort_unstable();
@@ -440,7 +441,6 @@ fn report_arm_reachability<'p, 'tcx>(
                     unreachable_pattern(cx.tcx, span, arm.hir_id, None);
                 }
             }
-            UsefulWithWitness(_) => bug!(),
         }
         if !arm.has_guard && catchall.is_none() && pat_is_catchall(arm.pat) {
             catchall = Some(arm.pat.span);
diff --git a/compiler/rustc_mir_build/src/thir/pattern/usefulness.rs b/compiler/rustc_mir_build/src/thir/pattern/usefulness.rs
index d1c9c3ea6bf..d8195eee4b8 100644
--- a/compiler/rustc_mir_build/src/thir/pattern/usefulness.rs
+++ b/compiler/rustc_mir_build/src/thir/pattern/usefulness.rs
@@ -679,7 +679,7 @@ impl SpanSet {
 }
 
 #[derive(Clone, Debug)]
-crate enum Usefulness<'tcx> {
+enum Usefulness<'tcx> {
     /// Pontentially carries a set of sub-branches that have been found to be unreachable. Used
     /// only in the presence of or-patterns, otherwise it stays empty.
     Useful(SpanSet),
@@ -1024,10 +1024,18 @@ crate struct MatchArm<'p, 'tcx> {
     crate has_guard: bool,
 }
 
+#[derive(Clone, Debug)]
+crate enum Reachability {
+    /// Potentially carries a set of sub-branches that have been found to be unreachable. Used only
+    /// in the presence of or-patterns, otherwise it stays empty.
+    Reachable(SpanSet),
+    Unreachable,
+}
+
 /// The output of checking a match for exhaustiveness and arm reachability.
 crate struct UsefulnessReport<'p, 'tcx> {
     /// For each arm of the input, whether that arm is reachable after the arms above it.
-    crate arm_usefulness: Vec<(MatchArm<'p, 'tcx>, Usefulness<'tcx>)>,
+    crate arm_usefulness: Vec<(MatchArm<'p, 'tcx>, Reachability)>,
     /// If the match is exhaustive, this is empty. If not, this contains witnesses for the lack of
     /// exhaustiveness.
     crate non_exhaustiveness_witnesses: Vec<super::Pat<'tcx>>,
@@ -1055,7 +1063,12 @@ crate fn compute_match_usefulness<'p, 'tcx>(
             if !arm.has_guard {
                 matrix.push(v);
             }
-            (arm, usefulness)
+            let reachability = match usefulness {
+                Useful(spans) => Reachability::Reachable(spans),
+                NotUseful => Reachability::Unreachable,
+                UsefulWithWitness(..) => bug!(),
+            };
+            (arm, reachability)
         })
         .collect();