@@ -603,9 +603,8 @@ impl<'a> TyLoweringContext<'a> {
603603 }
604604
605605 fn select_associated_type ( & self , res : Option < TypeNs > , segment : PathSegment < ' _ > ) -> Ty {
606- let ( def, res) = match ( self . resolver . generic_def ( ) , res) {
607- ( Some ( def) , Some ( res) ) => ( def, res) ,
608- _ => return TyKind :: Error . intern ( Interner ) ,
606+ let Some ( ( def, res) ) = self . resolver . generic_def ( ) . zip ( res) else {
607+ return TyKind :: Error . intern ( Interner ) ;
609608 } ;
610609 let ty = named_associated_type_shorthand_candidates (
611610 self . db ,
@@ -617,6 +616,21 @@ impl<'a> TyLoweringContext<'a> {
617616 return None ;
618617 }
619618
619+ let parent_subst = t. substitution . clone ( ) ;
620+ let parent_subst = match self . type_param_mode {
621+ ParamLoweringMode :: Placeholder => {
622+ // if we're lowering to placeholders, we have to put them in now.
623+ let generics = generics ( self . db . upcast ( ) , def) ;
624+ let s = generics. placeholder_subst ( self . db ) ;
625+ s. apply ( parent_subst, Interner )
626+ }
627+ ParamLoweringMode :: Variable => {
628+ // We need to shift in the bound vars, since
629+ // `named_associated_type_shorthand_candidates` does not do that.
630+ parent_subst. shifted_in_from ( Interner , self . in_binders )
631+ }
632+ } ;
633+
620634 // FIXME: `substs_from_path_segment()` pushes `TyKind::Error` for every parent
621635 // generic params. It's inefficient to splice the `Substitution`s, so we may want
622636 // that method to optionally take parent `Substitution` as we already know them at
@@ -632,22 +646,9 @@ impl<'a> TyLoweringContext<'a> {
632646
633647 let substs = Substitution :: from_iter (
634648 Interner ,
635- substs. iter ( Interner ) . take ( len_self) . chain ( t . substitution . iter ( Interner ) ) ,
649+ substs. iter ( Interner ) . take ( len_self) . chain ( parent_subst . iter ( Interner ) ) ,
636650 ) ;
637651
638- let substs = match self . type_param_mode {
639- ParamLoweringMode :: Placeholder => {
640- // if we're lowering to placeholders, we have to put
641- // them in now
642- let generics = generics ( self . db . upcast ( ) , def) ;
643- let s = generics. placeholder_subst ( self . db ) ;
644- s. apply ( substs, Interner )
645- }
646- ParamLoweringMode :: Variable => substs,
647- } ;
648- // We need to shift in the bound vars, since
649- // associated_type_shorthand_candidates does not do that
650- let substs = substs. shifted_in_from ( Interner , self . in_binders ) ;
651652 Some (
652653 TyKind :: Alias ( AliasTy :: Projection ( ProjectionTy {
653654 associated_ty_id : to_assoc_type_id ( associated_ty) ,
0 commit comments