diff options
author | Mark Wielaard <mark@klomp.org> | 2021-10-29 17:34:13 +0100 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2021-11-01 13:12:47 +0000 |
commit | 6e69ab6d0853da706441bc26ed6379348d1d463a (patch) | |
tree | 09d810d448b0c9651a2708ccbf9b42b3499ab718 /gcc | |
parent | 3c02a29f576ea423f7ec767aca12f3333e2814f0 (diff) | |
download | gcc-6e69ab6d0853da706441bc26ed6379348d1d463a.zip gcc-6e69ab6d0853da706441bc26ed6379348d1d463a.tar.gz gcc-6e69ab6d0853da706441bc26ed6379348d1d463a.tar.bz2 |
Get rid of lambda get_fields in struct
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/typecheck/rust-hir-type-check.cc | 11 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-tyty.cc | 91 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-tyty.h | 9 |
3 files changed, 50 insertions, 61 deletions
diff --git a/gcc/rust/typecheck/rust-hir-type-check.cc b/gcc/rust/typecheck/rust-hir-type-check.cc index 0febc6c..bd06473 100644 --- a/gcc/rust/typecheck/rust-hir-type-check.cc +++ b/gcc/rust/typecheck/rust-hir-type-check.cc @@ -201,16 +201,15 @@ TypeCheckStructExpr::visit (HIR::StructExprStructFields &struct_expr) // we have a struct base to assign the missing fields from. // the missing fields can be implicit FieldAccessExprs for the value std::set<std::string> missing_fields; - struct_path_resolved->iterate_fields ( - [&] (TyTy::StructFieldType *field) mutable -> bool { + for (auto &field : struct_path_resolved->get_fields ()) + { auto it = fields_assigned.find (field->get_name ()); if (it == fields_assigned.end ()) missing_fields.insert (field->get_name ()); - return true; - }); + } - // we can generate FieldAccessExpr or TupleAccessExpr for the values - // of the missing fields. + // we can generate FieldAccessExpr or TupleAccessExpr for the + // values of the missing fields. for (auto &missing : missing_fields) { HIR::Expr *receiver diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc index 91d3b5c..58d6727 100644 --- a/gcc/rust/typecheck/rust-tyty.cc +++ b/gcc/rust/typecheck/rust-tyty.cc @@ -721,54 +721,53 @@ ADTType::handle_substitions (SubstitutionArgumentMappings subst_mappings) sub.fill_param_ty (*arg.get_tyty (), subst_mappings.get_locus ()); } - adt->iterate_fields ([&] (StructFieldType *field) mutable -> bool { - auto fty = field->get_field_type (); - bool is_param_ty = fty->get_kind () == TypeKind::PARAM; - if (is_param_ty) - { - ParamType *p = static_cast<ParamType *> (fty); - - SubstitutionArg arg = SubstitutionArg::error (); - bool ok = subst_mappings.get_argument_for_symbol (p, &arg); - if (ok) - { - auto argt = arg.get_tyty (); - bool arg_is_param = argt->get_kind () == TyTy::TypeKind::PARAM; - bool arg_is_concrete = argt->get_kind () != TyTy::TypeKind::INFER; - - if (arg_is_param || arg_is_concrete) - { - auto new_field = argt->clone (); - new_field->set_ref (fty->get_ref ()); - field->set_field_type (new_field); - } - else - { - field->get_field_type ()->set_ty_ref (argt->get_ref ()); - } - } - } - else if (fty->has_subsititions_defined () - || fty->contains_type_parameters ()) - { - BaseType *concrete - = Resolver::SubstMapperInternal::Resolve (fty, subst_mappings); - - if (concrete->get_kind () == TyTy::TypeKind::ERROR) - { - rust_error_at (subst_mappings.get_locus (), - "Failed to resolve field substitution type: %s", - fty->as_string ().c_str ()); - return false; - } + for (auto &field : adt->fields) + { + auto fty = field->get_field_type (); + bool is_param_ty = fty->get_kind () == TypeKind::PARAM; + if (is_param_ty) + { + ParamType *p = static_cast<ParamType *> (fty); - auto new_field = concrete->clone (); - new_field->set_ref (fty->get_ref ()); - field->set_field_type (new_field); - } + SubstitutionArg arg = SubstitutionArg::error (); + bool ok = subst_mappings.get_argument_for_symbol (p, &arg); + if (ok) + { + auto argt = arg.get_tyty (); + bool arg_is_param = argt->get_kind () == TyTy::TypeKind::PARAM; + bool arg_is_concrete = argt->get_kind () != TyTy::TypeKind::INFER; - return true; - }); + if (arg_is_param || arg_is_concrete) + { + auto new_field = argt->clone (); + new_field->set_ref (fty->get_ref ()); + field->set_field_type (new_field); + } + else + { + field->get_field_type ()->set_ty_ref (argt->get_ref ()); + } + } + } + else if (fty->has_subsititions_defined () + || fty->contains_type_parameters ()) + { + BaseType *concrete + = Resolver::SubstMapperInternal::Resolve (fty, subst_mappings); + + if (concrete->get_kind () == TyTy::TypeKind::ERROR) + { + rust_error_at (subst_mappings.get_locus (), + "Failed to resolve field substitution type: %s", + fty->as_string ().c_str ()); + return adt; + } + + auto new_field = concrete->clone (); + new_field->set_ref (fty->get_ref ()); + field->set_field_type (new_field); + } + } return adt; } diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h index ef37dc6..3077281 100644 --- a/gcc/rust/typecheck/rust-tyty.h +++ b/gcc/rust/typecheck/rust-tyty.h @@ -1105,15 +1105,6 @@ public: std::vector<StructFieldType *> &get_fields () { return fields; } const std::vector<StructFieldType *> &get_fields () const { return fields; } - void iterate_fields (std::function<bool (StructFieldType *)> cb) - { - for (auto &f : fields) - { - if (!cb (f)) - return; - } - } - bool needs_generic_substitutions () const override final { return needs_substitution (); |