]> git.lizzy.rs Git - rust.git/commitdiff
Refined error message to truncate at 3 and hint at number of hidden patterns for...
authorVincent Esche <regexident@gmail.com>
Thu, 21 Jan 2016 19:52:11 +0000 (20:52 +0100)
committerVincent Esche <regexident@gmail.com>
Thu, 21 Jan 2016 21:33:27 +0000 (22:33 +0100)
src/librustc/middle/check_match.rs
src/test/compile-fail/non-exhaustive-pattern-witness.rs

index 100e78d2f4564e299d4f28999f36adc3a7673571..6ed576d209f2f8c87ea2135e212069325aa528cf 100644 (file)
@@ -392,19 +392,21 @@ fn check_exhaustive(cx: &MatchCheckCtxt, sp: Span, matrix: &Matrix, source: hir:
                     let pattern_strings: Vec<_> = witnesses.iter().map(|w| {
                         pat_to_string(w)
                     }).collect();
-                    let (tail, head) = pattern_strings.split_last().unwrap();
-                    const HEAD_LIMIT: usize = 9;
-                    let joined_patterns = match head.len() {
-                        0 => tail.clone(),
-                        1...HEAD_LIMIT => head.join("`, `") + "` and `" + tail,
+                    const LIMIT: usize = 3;
+                    let joined_patterns = match pattern_strings.len() {
+                        0 => unreachable!(),
+                        1 => format!("`{}`", pattern_strings[0]),
+                        2...LIMIT => {
+                            let (tail, head) = pattern_strings.split_last().unwrap();
+                            format!("`{}`", head.join("`, `") + "` and `" + tail)
+                        },
                         _ => {
-                            let head_iter = head.to_owned().into_iter();
-                            let truncated_head: Vec<_> = head_iter.take(HEAD_LIMIT).collect();
-                            truncated_head.join("`, `") + "`, … and `" + tail
+                            let (head, tail) = pattern_strings.split_at(LIMIT);
+                            format!("`{}` and {} more", head.join("`, `"), tail.len())
                         }
                     };
                     span_err!(cx.tcx.sess, sp, E0004,
-                        "non-exhaustive patterns: `{}` not covered",
+                        "non-exhaustive patterns: {} not covered",
                         joined_patterns
                     );
                 },
index a84d42f1a7028c9192e98e6abdb74826aca5c4d7..b986878f78396ae823bf9e3fac40e93486dd65f2 100644 (file)
@@ -32,10 +32,11 @@ enum Color {
     CustomRGBA { a: bool, r: u8, g: u8, b: u8 }
 }
 
-fn enum_with_two_missing_variants() {
+fn enum_with_single_missing_variant() {
     match Color::Red {
-    //~^ ERROR non-exhaustive patterns: `Red` and `Green` not covered
-        Color::CustomRGBA { .. } => ()
+    //~^ ERROR non-exhaustive patterns: `Red` not covered
+        Color::CustomRGBA { .. } => (),
+        Color::Green => ()
     }
 }
 
@@ -43,7 +44,7 @@ enum Direction {
     North, East, South, West
 }
 
-fn enum_with_three_or_more_missing_variants() {
+fn enum_with_multiple_missing_variants() {
     match Direction::North {
     //~^ ERROR non-exhaustive patterns: `East`, `South` and `West` not covered
         Direction::North => ()
@@ -56,7 +57,7 @@ enum ExcessiveEnum {
 
 fn enum_with_excessive_missing_variants() {
     match ExcessiveEnum::First {
-    //~^ ERROR `Sixth`, `Seventh`, `Eighth`, `Ninth`, `Tenth`, … and `Twelfth` not covered
+    //~^ ERROR `Second`, `Third`, `Fourth` and 8 more not covered
 
         ExcessiveEnum::First => ()
     }