Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored Field Error Function #2341

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions gcc/rust/typecheck/rust-hir-type-check-pattern.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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 ());
Expand All @@ -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 ());
Expand Down