about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2019-08-29 17:41:25 -0700
committerEsteban Küber <esteban@kuber.com.ar>2019-10-16 11:57:19 -0700
commitd2cb5a8c35cd40909f097bdbbc59fc870f0a8e91 (patch)
treefb270082ba95fbf93e14e5e2c4e42c45ecdc0843
parent916936c77488d0a75cc254b5bdc9a787c8ed8768 (diff)
downloadrust-d2cb5a8c35cd40909f097bdbbc59fc870f0a8e91.tar.gz
rust-d2cb5a8c35cd40909f097bdbbc59fc870f0a8e91.zip
Move lint emitter to its own method
-rw-r--r--src/librustc_mir/hair/pattern/_match.rs45
1 files changed, 27 insertions, 18 deletions
diff --git a/src/librustc_mir/hair/pattern/_match.rs b/src/librustc_mir/hair/pattern/_match.rs
index 1b3c824458e..48ff7fff5ed 100644
--- a/src/librustc_mir/hair/pattern/_match.rs
+++ b/src/librustc_mir/hair/pattern/_match.rs
@@ -1739,24 +1739,7 @@ fn split_grouped_constructors<'p, 'tcx>(
                 let mut borders: Vec<_> = row_borders.chain(ctor_borders).collect();
                 borders.sort_unstable();
 
-                if let (true, Some(hir_id)) = (!overlaps.is_empty(), hir_id) {
-                    let mut err = tcx.struct_span_lint_hir(
-                        lint::builtin::OVERLAPPING_PATTERNS,
-                        hir_id,
-                        ctor_range.span,
-                        "multiple patterns covering the same range",
-                    );
-                    err.span_label(ctor_range.span, "overlapping patterns");
-                    for int_range in overlaps {
-                        // Use the real type for user display of the ranges:
-                        err.span_label(int_range.span, &format!(
-                            "this range overlaps on `{}`",
-                            IntRange::range_to_ctor(tcx, ty, int_range.range, DUMMY_SP)
-                                .display(tcx),
-                        ));
-                    }
-                    err.emit();
-                }
+                lint_unreachable_patterns(tcx, hir_id, ctor_range, ty, overlaps);
 
                 // We're going to iterate through every pair of borders, making sure that each
                 // represents an interval of nonnegative length, and convert each such interval
@@ -1787,6 +1770,32 @@ fn split_grouped_constructors<'p, 'tcx>(
     split_ctors
 }
 
+fn lint_unreachable_patterns(
+    tcx: TyCtxt<'tcx>,
+    hir_id: Option<HirId>,
+    ctor_range: IntRange<'tcx>,
+    ty: Ty<'tcx>,
+    overlaps: Vec<IntRange<'tcx>>,
+) {
+    if let (true, Some(hir_id)) = (!overlaps.is_empty(), hir_id) {
+        let mut err = tcx.struct_span_lint_hir(
+            lint::builtin::OVERLAPPING_PATTERNS,
+            hir_id,
+            ctor_range.span,
+            "multiple patterns covering the same range",
+        );
+        err.span_label(ctor_range.span, "overlapping patterns");
+        for int_range in overlaps {
+            // Use the real type for user display of the ranges:
+            err.span_label(int_range.span, &format!(
+                "this range overlaps on `{}`",
+                IntRange::range_to_ctor(tcx, ty, int_range.range, DUMMY_SP).display(tcx),
+            ));
+        }
+        err.emit();
+    }
+}
+
 fn constructor_covered_by_range<'tcx>(
     tcx: TyCtxt<'tcx>,
     param_env: ty::ParamEnv<'tcx>,