@@ -35,24 +35,6 @@ fn initial_self_pred<'tcx, Id: ItemId>(
3535 }
3636}
3737
38- #[ tracing:: instrument( level = "trace" , skip( elab_ctx, state) ) ]
39- fn parents_trait_predicates < ' tcx , Id : ItemId > (
40- elab_ctx : ElaborationCtx < ' tcx , Id > ,
41- state : & Id :: State < ' tcx > ,
42- self_trait_ref : PolyTraitRef < ' tcx > ,
43- ) -> Vec < PolyTraitRef < ' tcx > > {
44- let tcx = elab_ctx. tcx ;
45- let def_id = Id :: from_rust_def_id ( state, self_trait_ref. def_id ( ) ) ;
46- ItemPredicates :: implied ( elab_ctx, state, def_id)
47- . iter ( )
48- // Substitute with the `self` args so that the clause makes sense in the
49- // outside context.
50- . map ( |pred| pred. clause . instantiate_supertrait ( tcx, self_trait_ref) )
51- . filter_map ( |pred| pred. as_trait_clause ( ) )
52- . map ( |pred| pred. to_poly_trait_ref ( ) )
53- . collect ( )
54- }
55-
5638/// A trait proof we have in our context.
5739#[ derive( Debug , Clone ) ]
5840struct Candidate < ' tcx , Id : ItemId = DefId > {
@@ -321,16 +303,34 @@ impl<'tcx, Id: ItemId> PredicateSearcher<'tcx, Id> {
321303 new_candidates : Vec < Candidate < ' tcx , Id > > ,
322304 ) {
323305 let elab_ctx = self . elab_ctx ;
306+ let tcx = elab_ctx. tcx ;
324307 // Then recursively add their parents. This way ensures a breadth-first order,
325308 // which means we select the shortest path when looking up predicates.
326309 self . insert_candidates (
327310 state,
328311 new_candidates. into_iter ( ) . flat_map ( |candidate| {
329- parents_trait_predicates ( elab_ctx, state, candidate. pred )
312+ let def_id = Id :: from_rust_def_id ( state, candidate. pred . def_id ( ) ) ;
313+ ItemPredicates :: implied ( elab_ctx, state, def_id)
314+ . predicates
330315 . into_iter ( )
316+ . filter ( |pred| pred. clause . as_trait_clause ( ) . is_some ( ) )
331317 . enumerate ( )
332- . map ( move |( index, parent_pred) | {
333- candidate. push ( elab_ctx, parent_pred, ImpliedPredicate :: Parent { index } )
318+ . map ( |( index, pred) | {
319+ let pred_id = ImpliedPredicate :: Parent {
320+ index,
321+ bound_region_count : pred. clause . kind ( ) . bound_vars ( ) . len ( ) ,
322+ } ;
323+ ( pred_id, pred)
324+ } )
325+ // Substitute with the `self` args so that the clause makes sense in the
326+ // outside context. This merges nested region binders.
327+ . map ( move |( pred_id, pred) | {
328+ let pred = pred. clause . instantiate_supertrait ( tcx, candidate. pred ) ;
329+ ( pred_id, pred)
330+ } )
331+ . map ( move |( pred_id, pred) | {
332+ let pred = pred. as_trait_clause ( ) . unwrap ( ) . to_poly_trait_ref ( ) ;
333+ candidate. push ( elab_ctx, pred, pred_id)
334334 } )
335335 } ) ,
336336 ) ;
@@ -372,26 +372,26 @@ impl<'tcx, Id: ItemId> PredicateSearcher<'tcx, Id> {
372372 ItemPredicates :: implied ( self . elab_ctx , state, Id :: from_rust_def_id ( state, * def_id) ) ;
373373 let item_bounds = item_bounds
374374 . iter_trait_clauses ( )
375- // Substitute the item generics
376- . map ( |( _, tref) | {
377- EarlyBinder :: bind ( tcx, tref)
375+ . enumerate ( )
376+ . map ( |( index, ( _, tref) ) | {
377+ let bound_region_count = tref. bound_vars ( ) . len ( ) ;
378+ // Substitute the item generics
379+ let pred = EarlyBinder :: bind ( tcx, tref)
378380 . instantiate ( tcx, args)
379- . skip_normalization ( )
380- } )
381- . enumerate ( ) ;
381+ . skip_normalization ( ) ;
382+ let pred_id = ImpliedPredicate :: AssocItem {
383+ item : item_ref. clone ( ) ,
384+ index,
385+ bound_region_count,
386+ } ;
387+ ( pred_id, pred)
388+ } ) ;
382389
383390 // Add all the bounds on the corresponding associated item.
384391 self . insert_candidates (
385392 state,
386- item_bounds. map ( |( index, pred) | {
387- Candidate :: from_trait_proof ( proof. push (
388- elab_ctx,
389- pred,
390- ImpliedPredicate :: AssocItem {
391- item : item_ref. clone ( ) ,
392- index,
393- } ,
394- ) )
393+ item_bounds. map ( |( pred_id, pred) | {
394+ Candidate :: from_trait_proof ( proof. push ( elab_ctx, pred, pred_id) )
395395 } ) ,
396396 ) ;
397397 }
0 commit comments