about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-08-24 17:34:15 +0200
committerMazdak Farrokhzad <twingoow@gmail.com>2019-08-24 19:57:05 +0200
commit25f605ae99b1ac3565fc0bb65d97083f39444d60 (patch)
tree9a05bea9340968a86fe653bde62ae45a417efee8
parent729fbeb70b9aabc6df58f0cc3601402b44663cf2 (diff)
downloadrust-25f605ae99b1ac3565fc0bb65d97083f39444d60.tar.gz
rust-25f605ae99b1ac3565fc0bb65d97083f39444d60.zip
typeck/pat.rs: extract `error_field_already_bound`.
-rw-r--r--src/librustc_typeck/check/pat.rs20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/librustc_typeck/check/pat.rs b/src/librustc_typeck/check/pat.rs
index ff1500e6bd8..0aed814b2da 100644
--- a/src/librustc_typeck/check/pat.rs
+++ b/src/librustc_typeck/check/pat.rs
@@ -774,14 +774,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
             let ident = tcx.adjust_ident(field.ident, variant.def_id);
             let field_ty = match used_fields.entry(ident) {
                 Occupied(occupied) => {
-                    struct_span_err!(tcx.sess, span, E0025,
-                                     "field `{}` bound multiple times \
-                                      in the pattern",
-                                     field.ident)
-                        .span_label(span,
-                                    format!("multiple uses of `{}` in pattern", field.ident))
-                        .span_label(*occupied.get(), format!("first use of `{}`", field.ident))
-                        .emit();
+                    self.error_field_already_bound(span, field.ident, *occupied.get());
                     no_field_errors = false;
                     tcx.types.err
                 }
@@ -912,6 +905,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
         no_field_errors
     }
 
+    fn error_field_already_bound(&self, span: Span, ident: ast::Ident, other_field: Span) {
+        struct_span_err!(
+            self.tcx.sess, span, E0025,
+            "field `{}` bound multiple times in the pattern",
+            ident
+        )
+        .span_label(span, format!("multiple uses of `{}` in pattern", ident))
+        .span_label(other_field, format!("first use of `{}`", ident))
+        .emit();
+    }
+
     fn check_pat_box(
         &self,
         span: Span,