From 408e9c03105b942f0f7abebe916e35c0a9fefaa7 Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Tue, 4 Apr 2023 16:13:18 +0100 Subject: gccrs: never re-setup trait item bound with a dyn object It results in a recursive generic Param cycle. gcc/rust/ChangeLog: * typecheck/rust-hir-path-probe.cc: dont subst with a dynamic object Signed-off-by: Philip Herron --- gcc/rust/typecheck/rust-hir-path-probe.cc | 35 ++++++++----------------------- 1 file changed, 9 insertions(+), 26 deletions(-) (limited to 'gcc/rust') diff --git a/gcc/rust/typecheck/rust-hir-path-probe.cc b/gcc/rust/typecheck/rust-hir-path-probe.cc index 049c91e..b38282c 100644 --- a/gcc/rust/typecheck/rust-hir-path-probe.cc +++ b/gcc/rust/typecheck/rust-hir-path-probe.cc @@ -341,36 +341,16 @@ PathProbeType::process_associated_trait_for_candidates ( break; } - TyTy::BaseType *trait_item_tyty = trait_item_ref->get_tyty (); + const TyTy::TypeBoundPredicate p (*trait_ref, Location ()); + TyTy::TypeBoundPredicateItem item (&p, trait_item_ref); - // we can substitute the Self with the receiver here - if (trait_item_tyty->get_kind () == TyTy::TypeKind::FNDEF) - { - TyTy::FnType *fn = static_cast (trait_item_tyty); - TyTy::SubstitutionParamMapping *param = nullptr; - for (auto ¶m_mapping : fn->get_substs ()) - { - const HIR::TypeParam &type_param = param_mapping.get_generic_param (); - if (type_param.get_type_representation ().compare ("Self") == 0) - { - param = ¶m_mapping; - break; - } - } - rust_assert (param != nullptr); - - std::vector mappings; - mappings.push_back (TyTy::SubstitutionArg (param, receiver->clone ())); - - Location locus; // FIXME - TyTy::SubstitutionArgumentMappings args (std::move (mappings), {}, locus); - trait_item_tyty = SubstMapperInternal::Resolve (trait_item_tyty, args); - } + TyTy::BaseType *trait_item_tyty = item.get_raw_item ()->get_tyty (); + if (receiver->get_kind () != TyTy::DYNAMIC) + trait_item_tyty = item.get_tyty_for_receiver (receiver); PathProbeCandidate::TraitItemCandidate trait_item_candidate{trait_ref, trait_item_ref, impl}; - PathProbeCandidate candidate{candidate_type, trait_item_tyty, trait_item_ref->get_locus (), trait_item_candidate}; @@ -411,7 +391,10 @@ PathProbeType::process_predicate_for_candidates ( break; } - TyTy::BaseType *trait_item_tyty = item.get_tyty_for_receiver (receiver); + TyTy::BaseType *trait_item_tyty = item.get_raw_item ()->get_tyty (); + if (receiver->get_kind () != TyTy::DYNAMIC) + trait_item_tyty = item.get_tyty_for_receiver (receiver); + PathProbeCandidate::TraitItemCandidate trait_item_candidate{trait_ref, trait_item_ref, nullptr}; -- cgit v1.1