@@ -1970,7 +1970,8 @@ fn named_associated_type_shorthand_candidates<'db, R>(
19701970 let mut search = |t : TraitRef < ' db > | -> Option < R > {
19711971 let trait_id = t. def_id . 0 ;
19721972 let mut checked_traits = FxHashSet :: default ( ) ;
1973- let mut check_trait = |trait_id : TraitId | {
1973+ let mut check_trait = |trait_ref : TraitRef < ' db > | {
1974+ let trait_id = trait_ref. def_id . 0 ;
19741975 let name = & db. trait_signature ( trait_id) . name ;
19751976 tracing:: debug!( ?trait_id, ?name) ;
19761977 if !checked_traits. insert ( trait_id) {
@@ -1981,37 +1982,39 @@ fn named_associated_type_shorthand_candidates<'db, R>(
19811982 tracing:: debug!( ?data. items) ;
19821983 for ( name, assoc_id) in & data. items {
19831984 if let & AssocItemId :: TypeAliasId ( alias) = assoc_id
1984- && let Some ( ty) = check_alias ( name, t , alias)
1985+ && let Some ( ty) = check_alias ( name, trait_ref , alias)
19851986 {
19861987 return Some ( ty) ;
19871988 }
19881989 }
19891990 None
19901991 } ;
1991- let mut stack: SmallVec < [ _ ; 4 ] > = smallvec ! [ trait_id ] ;
1992- while let Some ( trait_def_id ) = stack. pop ( ) {
1993- if let Some ( alias) = check_trait ( trait_def_id ) {
1992+ let mut stack: SmallVec < [ _ ; 4 ] > = smallvec ! [ t ] ;
1993+ while let Some ( trait_ref ) = stack. pop ( ) {
1994+ if let Some ( alias) = check_trait ( trait_ref ) {
19941995 return Some ( alias) ;
19951996 }
19961997 for pred in generic_predicates_filtered_by (
19971998 db,
1998- GenericDefId :: TraitId ( trait_def_id ) ,
1999+ GenericDefId :: TraitId ( trait_ref . def_id . 0 ) ,
19992000 PredicateFilter :: SelfTrait ,
20002001 // We are likely in the midst of lowering generic predicates of `def`.
20012002 // So, if we allow `pred == def` we might fall into an infinite recursion.
20022003 // Actually, we have already checked for the case `pred == def` above as we started
20032004 // with a stack including `trait_id`
2004- |pred| pred != def && pred == GenericDefId :: TraitId ( trait_def_id ) ,
2005+ |pred| pred != def && pred == GenericDefId :: TraitId ( trait_ref . def_id . 0 ) ,
20052006 )
20062007 . 0
20072008 . deref ( )
20082009 {
20092010 tracing:: debug!( ?pred) ;
2010- let trait_id = match pred. kind ( ) . skip_binder ( ) {
2011- rustc_type_ir:: ClauseKind :: Trait ( pred) => pred. def_id ( ) ,
2011+ let sup_trait_ref = match pred. kind ( ) . skip_binder ( ) {
2012+ rustc_type_ir:: ClauseKind :: Trait ( pred) => pred. trait_ref ,
20122013 _ => continue ,
20132014 } ;
2014- stack. push ( trait_id. 0 ) ;
2015+ let sup_trait_ref =
2016+ EarlyBinder :: bind ( sup_trait_ref) . instantiate ( interner, trait_ref. args ) ;
2017+ stack. push ( sup_trait_ref) ;
20152018 }
20162019 tracing:: debug!( ?stack) ;
20172020 }
0 commit comments