about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/librustc_mir/hair/pattern/check_match.rs34
1 files changed, 19 insertions, 15 deletions
diff --git a/src/librustc_mir/hair/pattern/check_match.rs b/src/librustc_mir/hair/pattern/check_match.rs
index c58f5d747e0..245e7534add 100644
--- a/src/librustc_mir/hair/pattern/check_match.rs
+++ b/src/librustc_mir/hair/pattern/check_match.rs
@@ -463,21 +463,7 @@ fn check_exhaustive<'tcx>(
         pats.iter().map(|w| w.single_pattern()).collect()
     };
 
-    const LIMIT: usize = 3;
-    let joined_patterns = match witnesses.len() {
-        0 => bug!(),
-        1 => format!("`{}`", witnesses[0]),
-        2..=LIMIT => {
-            let (tail, head) = witnesses.split_last().unwrap();
-            let head: Vec<_> = head.iter().map(|w| w.to_string()).collect();
-            format!("`{}` and `{}`", head.join("`, `"), tail)
-        }
-        _ => {
-            let (head, tail) = witnesses.split_at(LIMIT);
-            let head: Vec<_> = head.iter().map(|w| w.to_string()).collect();
-            format!("`{}` and {} more", head.join("`, `"), tail.len())
-        }
-    };
+    let joined_patterns = joined_uncovered_patterns(&witnesses);
 
     let mut err = create_e0004(cx.tcx.sess, sp, format!(
         "non-exhaustive patterns: {} not covered",
@@ -501,6 +487,24 @@ fn check_exhaustive<'tcx>(
     err.emit();
 }
 
+fn joined_uncovered_patterns(witnesses: &[&Pattern<'_>]) -> String {
+    const LIMIT: usize = 3;
+    match witnesses.len() {
+        0 => bug!(),
+        1 => format!("`{}`", witnesses[0]),
+        2..=LIMIT => {
+            let (tail, head) = witnesses.split_last().unwrap();
+            let head: Vec<_> = head.iter().map(|w| w.to_string()).collect();
+            format!("`{}` and `{}`", head.join("`, `"), tail)
+        }
+        _ => {
+            let (head, tail) = witnesses.split_at(LIMIT);
+            let head: Vec<_> = head.iter().map(|w| w.to_string()).collect();
+            format!("`{}` and {} more", head.join("`, `"), tail.len())
+        }
+    }
+}
+
 fn adt_defined_here(cx: &mut MatchCheckCtxt<'_, '_>, ty: Ty<'_>, err: &mut DiagnosticBuilder<'_>) {
     if let ty::Adt(def, _) = ty.sty {
         if let Some(sp) = cx.tcx.hir().span_if_local(def.did) {