@@ -126,9 +126,11 @@ MethodResolver::Try (const TyTy::BaseType *r,
126126  PathProbeCandidate c = PathProbeCandidate::get_error  ();
127127  const  std::vector<TyTy::TypeBoundPredicate> &specified_bounds
128128    = r->get_specified_bounds  ();
129+   const  std::vector<MethodResolver::predicate_candidate> predicate_items
130+     = get_predicate_items  (segment_name, *r, specified_bounds);
129131
130132  //  1. try raw
131-   MethodResolver raw  (*r, segment_name, specified_bounds );
133+   MethodResolver raw  (*r, segment_name, predicate_items );
132134  c = raw.select  ();
133135  if  (!c.is_error  ())
134136    {
@@ -139,7 +141,7 @@ MethodResolver::Try (const TyTy::BaseType *r,
139141  TyTy::ReferenceType *r1
140142    = new  TyTy::ReferenceType  (r->get_ref  (), TyTy::TyVar  (r->get_ref  ()),
141143			       Mutability::Imm);
142-   MethodResolver imm_ref  (*r1, segment_name, specified_bounds );
144+   MethodResolver imm_ref  (*r1, segment_name, predicate_items );
143145  c = imm_ref.select  ();
144146  if  (!c.is_error  ())
145147    {
@@ -152,7 +154,7 @@ MethodResolver::Try (const TyTy::BaseType *r,
152154  TyTy::ReferenceType *r2
153155    = new  TyTy::ReferenceType  (r->get_ref  (), TyTy::TyVar  (r->get_ref  ()),
154156			       Mutability::Mut);
155-   MethodResolver mut_ref  (*r2, segment_name, specified_bounds );
157+   MethodResolver mut_ref  (*r2, segment_name, predicate_items );
156158  c = mut_ref.select  ();
157159  if  (!c.is_error  ())
158160    {
@@ -288,27 +290,6 @@ MethodResolver::select ()
288290    TyTy::FnType *fntype;
289291  };
290292
291-   std::vector<precdicate_candidate> predicate_items;
292-   for  (auto  &bound : specified_bounds)
293-     {
294-       TyTy::TypeBoundPredicateItem lookup
295- 	= bound.lookup_associated_item  (segment_name.as_string  ());
296-       if  (lookup.is_error  ())
297- 	continue ;
298- 
299-       bool  is_fn = lookup.get_raw_item  ()->get_trait_item_type  ()
300- 		   == TraitItemReference::TraitItemType::FN;
301-       if  (!is_fn)
302- 	continue ;
303- 
304-       TyTy::BaseType *ty = lookup.get_raw_item  ()->get_tyty  ();
305-       rust_assert  (ty->get_kind  () == TyTy::TypeKind::FNDEF);
306-       TyTy::FnType *fnty = static_cast <TyTy::FnType *> (ty);
307- 
308-       precdicate_candidate candidate{lookup, fnty};
309-       predicate_items.push_back  (candidate);
310-     }
311- 
312293  for  (auto  impl_item : inherent_impl_fns)
313294    {
314295      TyTy::FnType *fn = impl_item.ty ;
@@ -342,9 +323,9 @@ MethodResolver::select ()
342323	}
343324    }
344325
345-   for  (auto  predicate : predicate_items)
326+   for  (const   auto  & predicate : predicate_items)
346327    {
347-       TyTy::FnType *fn = predicate.fntype ;
328+       const   TyTy::FnType *fn = predicate.fntype ;
348329      rust_assert  (fn->is_method  ());
349330
350331      TyTy::BaseType *fn_self = fn->get_self_type  ();
@@ -355,20 +336,41 @@ MethodResolver::select ()
355336	  const  TraitItemReference *trait_item
356337	    = predicate.lookup .get_raw_item  ();
357338
358- 	  TyTy::BaseType *subst = predicate.lookup .get_tyty_for_receiver  (
359- 	    receiver.get_root  (),
360- 	    predicate.lookup .get_parent  ()->get_generic_args  ());
361- 
362339	  PathProbeCandidate::TraitItemCandidate c{trait_ref, trait_item,
363340						   nullptr };
364341	  return  PathProbeCandidate  (
365- 	    PathProbeCandidate::CandidateType::TRAIT_FUNC, subst ,
342+ 	    PathProbeCandidate::CandidateType::TRAIT_FUNC, fn-> clone  () ,
366343	    trait_item->get_locus  (), c);
367344	}
368345    }
369346
370347  return  PathProbeCandidate::get_error  ();
371348}
372349
350+ std::vector<MethodResolver::predicate_candidate>
351+ MethodResolver::get_predicate_items  (
352+   const  HIR::PathIdentSegment &segment_name, const  TyTy::BaseType &receiver,
353+   const  std::vector<TyTy::TypeBoundPredicate> &specified_bounds)
354+ {
355+   std::vector<predicate_candidate> predicate_items;
356+   for  (auto  &bound : specified_bounds)
357+     {
358+       TyTy::TypeBoundPredicateItem lookup
359+ 	= bound.lookup_associated_item  (segment_name.as_string  ());
360+       if  (lookup.is_error  ())
361+ 	continue ;
362+ 
363+       TyTy::BaseType *ty = lookup.get_tyty_for_receiver  (&receiver);
364+       if  (ty->get_kind  () == TyTy::TypeKind::FNDEF)
365+ 	{
366+ 	  TyTy::FnType *fnty = static_cast <TyTy::FnType *> (ty);
367+ 	  predicate_candidate candidate{lookup, fnty};
368+ 	  predicate_items.push_back  (candidate);
369+ 	}
370+     }
371+ 
372+   return  predicate_items;
373+ }
374+ 
373375} //  namespace Resolver
374376} //  namespace Rust
0 commit comments