]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: never re-setup trait item bound with a dyn object
authorPhilip Herron <herron.philip@googlemail.com>
Tue, 4 Apr 2023 15:13:18 +0000 (16:13 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 17:28:46 +0000 (18:28 +0100)
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 <herron.philip@googlemail.com>
gcc/rust/typecheck/rust-hir-path-probe.cc

index 049c91e97b3920f659a72b8cd0d3621886f8e508..b38282c487c9b5e8f193fe648710d87522b0638d 100644 (file)
@@ -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<TyTy::FnType *> (trait_item_tyty);
-      TyTy::SubstitutionParamMapping *param = nullptr;
-      for (auto &param_mapping : fn->get_substs ())
-       {
-         const HIR::TypeParam &type_param = param_mapping.get_generic_param ();
-         if (type_param.get_type_representation ().compare ("Self") == 0)
-           {
-             param = &param_mapping;
-             break;
-           }
-       }
-      rust_assert (param != nullptr);
-
-      std::vector<TyTy::SubstitutionArg> 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};