]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: refactored field error function
authorMuhammad Mahad <mahadtxt@gmail.com>
Thu, 29 Jun 2023 14:24:00 +0000 (19:24 +0500)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 17:49:29 +0000 (18:49 +0100)
Refactored field error function into one funciton
Fixes #2336

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-pattern.cc (emit_invalid_field_error): Refactored Field
Error Function
(TypeCheckPattern::visit): called emit_invalid_field_error function

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
gcc/rust/typecheck/rust-hir-type-check-pattern.cc

index 7854780cc9469982855fdfc664f3066c9ff2cf7e..a740805fb7fbf9cd40f4876475e3da1f32efc0e5 100644 (file)
@@ -139,6 +139,15 @@ TypeCheckPattern::visit (HIR::TupleStructPattern &pattern)
     }
 }
 
+void
+emit_invalid_field_error (Location loc, Rust::TyTy::VariantDef *variant,
+                         const std::string &name)
+{
+  rust_error_at (loc, ErrorCode ("E0026"),
+                "variant %s does not have a field named %s",
+                variant->get_identifier ().c_str (), name.c_str ());
+}
+
 void
 TypeCheckPattern::visit (HIR::StructPattern &pattern)
 {
@@ -204,10 +213,8 @@ TypeCheckPattern::visit (HIR::StructPattern &pattern)
            if (!variant->lookup_field (ident.get_identifier ().as_string (),
                                        &field, nullptr))
              {
-               rust_error_at (ident.get_locus (), ErrorCode ("E0026"),
-                              "variant %s does not have a field named %s",
-                              variant->get_identifier ().c_str (),
-                              ident.get_identifier ().as_string ().c_str ());
+               emit_invalid_field_error (ident.get_locus (), variant,
+                                         ident.get_identifier ().as_string ());
                break;
              }
            named_fields.push_back (ident.get_identifier ().as_string ());
@@ -225,10 +232,8 @@ TypeCheckPattern::visit (HIR::StructPattern &pattern)
            if (!variant->lookup_field (ident.get_identifier ().as_string (),
                                        &field, nullptr))
              {
-               rust_error_at (ident.get_locus (), ErrorCode ("E0026"),
-                              "variant %s does not have a field named %s",
-                              variant->get_identifier ().c_str (),
-                              ident.get_identifier ().as_string ().c_str ());
+               emit_invalid_field_error (ident.get_locus (), variant,
+                                         ident.get_identifier ().as_string ());
                break;
              }
            named_fields.push_back (ident.get_identifier ().as_string ());