about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJonathan Turner <jonathandturner@users.noreply.github.com>2016-08-08 13:25:56 -0700
committerGitHub <noreply@github.com>2016-08-08 13:25:56 -0700
commit7979da0783a0052cbcdbebd0594c5518eae7fb9c (patch)
treec7ba7ab6bca25d13340bd9a7af2f61b8bd7795ed
parentdd3817290376e3b31cd703a431deb4f6871728da (diff)
parent2c563c69f40a140e82e2d653bafd9e4f88621f30 (diff)
downloadrust-7979da0783a0052cbcdbebd0594c5518eae7fb9c.tar.gz
rust-7979da0783a0052cbcdbebd0594c5518eae7fb9c.zip
Rollup merge of #35446 - pcn:update-E0023-to-new-format, r=jonathandturner
Update E0023 to the new format

Added some extra code to check for the appropriate ending for numbers ==
1 vs. not 1 in error messages.

Added an extra test so that the plural suffix is seen and exercised.
-rw-r--r--src/librustc_typeck/check/_match.rs21
-rw-r--r--src/test/compile-fail/E0023.rs5
2 files changed, 22 insertions, 4 deletions
diff --git a/src/librustc_typeck/check/_match.rs b/src/librustc_typeck/check/_match.rs
index fe68690d4e9..2e8fd3dc276 100644
--- a/src/librustc_typeck/check/_match.rs
+++ b/src/librustc_typeck/check/_match.rs
@@ -633,10 +633,23 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
                 self.check_pat(&subpat, field_ty);
             }
         } else {
-            span_err!(tcx.sess, pat.span, E0023,
-                      "this pattern has {} field{s}, but the corresponding {} has {} field{s}",
-                      subpats.len(), def.kind_name(), variant.fields.len(),
-                      s = if variant.fields.len() == 1 {""} else {"s"});
+            let subpats_ending = if subpats.len() == 1 {
+                ""
+            } else {
+                "s"
+            };
+            let fields_ending = if variant.fields.len() == 1 {
+                ""
+            } else {
+                "s"
+            };
+            struct_span_err!(tcx.sess, pat.span, E0023,
+                             "this pattern has {} field{}, but the corresponding {} has {} field{}",
+                             subpats.len(), subpats_ending, def.kind_name(),
+                             variant.fields.len(),  fields_ending)
+                .span_label(pat.span, &format!("expected {} field{}, found {}",
+                                               variant.fields.len(), fields_ending, subpats.len()))
+                .emit();
             on_error();
         }
     }
diff --git a/src/test/compile-fail/E0023.rs b/src/test/compile-fail/E0023.rs
index 05f126baf9a..c3623e3177b 100644
--- a/src/test/compile-fail/E0023.rs
+++ b/src/test/compile-fail/E0023.rs
@@ -13,10 +13,15 @@ enum Fruit {
     Pear(u32),
 }
 
+
 fn main() {
     let x = Fruit::Apple(String::new(), String::new());
     match x {
         Fruit::Apple(a) => {}, //~ ERROR E0023
+                               //~| NOTE expected 2 fields, found 1
         Fruit::Apple(a, b, c) => {}, //~ ERROR E0023
+                                     //~| NOTE expected 2 fields, found 3
+        Fruit::Pear(1, 2) => {}, //~ ERROR E0023
+                                 //~| NOTE expected 1 field, found 2
     }
 }