]> git.lizzy.rs Git - rust.git/commitdiff
typeck/pat.rs: extract `error_field_already_bound`.
authorMazdak Farrokhzad <twingoow@gmail.com>
Sat, 24 Aug 2019 15:34:15 +0000 (17:34 +0200)
committerMazdak Farrokhzad <twingoow@gmail.com>
Sat, 24 Aug 2019 17:57:05 +0000 (19:57 +0200)
src/librustc_typeck/check/pat.rs

index ff1500e6bd87762c55074e31d2e88e02e2c96bf2..0aed814b2da9b04ac3f06cb31da873a57b29e2ce 100644 (file)
@@ -774,14 +774,7 @@ fn check_struct_pat_fields(
             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 @@ fn check_struct_pat_fields(
         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,