Skip to content

Commit

Permalink
Remove lambdas with Hir::TupleStruct (Rust-GCC#707)
Browse files Browse the repository at this point in the history
  • Loading branch information
dafaust committed Oct 7, 2021
1 parent 431a389 commit 618cea1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 33 deletions.
9 changes: 0 additions & 9 deletions gcc/rust/hir/tree/rust-hir-item.h
Original file line number Diff line number Diff line change
Expand Up @@ -1603,15 +1603,6 @@ class TupleStruct : public Struct
std::vector<TupleField> &get_fields () { return fields; }
const std::vector<TupleField> &get_fields () const { return fields; }

void iterate (std::function<bool (TupleField &)> cb)
{
for (auto &field : fields)
{
if (!cb (field))
return;
}
}

protected:
/* Use covariance to implement clone function as returning this object
* rather than base */
Expand Down
26 changes: 14 additions & 12 deletions gcc/rust/typecheck/rust-hir-type-check-stmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,18 @@ class TypeCheckStmt : public TypeCheckBase
std::vector<TyTy::StructFieldType *> fields;

size_t idx = 0;
struct_decl.iterate ([&] (HIR::TupleField &field) mutable -> bool {
TyTy::BaseType *field_type
= TypeCheckType::Resolve (field.get_field_type ().get ());
TyTy::StructFieldType *ty_field
= new TyTy::StructFieldType (field.get_mappings ().get_hirid (),
std::to_string (idx), field_type);
fields.push_back (ty_field);
context->insert_type (field.get_mappings (), ty_field->get_field_type ());
idx++;
return true;
});
for (auto &field : struct_decl.get_fields ())
{
TyTy::BaseType *field_type
= TypeCheckType::Resolve (field.get_field_type ().get ());
TyTy::StructFieldType *ty_field
= new TyTy::StructFieldType (field.get_mappings ().get_hirid (),
std::to_string (idx), field_type);
fields.push_back (ty_field);
context->insert_type (field.get_mappings (),
ty_field->get_field_type ());
idx++;
}

TyTy::BaseType *type
= new TyTy::ADTType (struct_decl.get_mappings ().get_hirid (),
Expand Down Expand Up @@ -204,7 +205,8 @@ class TypeCheckStmt : public TypeCheckBase
= new TyTy::StructFieldType (field.get_mappings ().get_hirid (),
field.get_field_name (), field_type);
fields.push_back (ty_field);
context->insert_type (field.get_mappings (), ty_field->get_field_type ());
context->insert_type (field.get_mappings (),
ty_field->get_field_type ());
}

TyTy::BaseType *type
Expand Down
26 changes: 14 additions & 12 deletions gcc/rust/typecheck/rust-hir-type-check-toplevel.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,18 @@ class TypeCheckTopLevel : public TypeCheckBase
std::vector<TyTy::StructFieldType *> fields;

size_t idx = 0;
struct_decl.iterate ([&] (HIR::TupleField &field) mutable -> bool {
TyTy::BaseType *field_type
= TypeCheckType::Resolve (field.get_field_type ().get ());
TyTy::StructFieldType *ty_field
= new TyTy::StructFieldType (field.get_mappings ().get_hirid (),
std::to_string (idx), field_type);
fields.push_back (ty_field);
context->insert_type (field.get_mappings (), ty_field->get_field_type ());
idx++;
return true;
});
for (auto &field : struct_decl.get_fields ())
{
TyTy::BaseType *field_type
= TypeCheckType::Resolve (field.get_field_type ().get ());
TyTy::StructFieldType *ty_field
= new TyTy::StructFieldType (field.get_mappings ().get_hirid (),
std::to_string (idx), field_type);
fields.push_back (ty_field);
context->insert_type (field.get_mappings (),
ty_field->get_field_type ());
idx++;
}

TyTy::BaseType *type
= new TyTy::ADTType (struct_decl.get_mappings ().get_hirid (),
Expand Down Expand Up @@ -145,7 +146,8 @@ class TypeCheckTopLevel : public TypeCheckBase
= new TyTy::StructFieldType (field.get_mappings ().get_hirid (),
field.get_field_name (), field_type);
fields.push_back (ty_field);
context->insert_type (field.get_mappings (), ty_field->get_field_type ());
context->insert_type (field.get_mappings (),
ty_field->get_field_type ());
}

TyTy::BaseType *type
Expand Down

0 comments on commit 618cea1

Please sign in to comment.