@@ -175,19 +175,31 @@ fn const_arg_anon_type_of<'tcx>(tcx: TyCtxt<'tcx>, arg_hir_id: HirId, span: Span
175175 // arm would handle this.
176176 //
177177 // I believe this match arm is only needed for GAT but I am not 100% sure - BoxyUwU
178- Node :: Ty ( hir_ty @ hir:: Ty { kind : TyKind :: Path ( QPath :: TypeRelative ( _ , segment) ) , .. } ) => {
178+ Node :: Ty ( hir_ty @ hir:: Ty { kind : TyKind :: Path ( QPath :: TypeRelative ( ty , segment) ) , .. } ) => {
179179 // Find the Item containing the associated type so we can create an ItemCtxt.
180180 // Using the ItemCtxt lower the HIR for the unresolved assoc type into a
181181 // ty which is a fully resolved projection.
182182 // For the code example above, this would mean lowering `Self::Assoc<3>`
183183 // to a ty::Alias(ty::Projection, `<Self as Foo>::Assoc<3>`).
184- let item_def_id = tcx
185- . hir ( )
186- . parent_owner_iter ( arg_hir_id)
187- . find ( |( _, node) | matches ! ( node, OwnerNode :: Item ( _) ) )
188- . unwrap ( )
189- . 0
190- . def_id ;
184+ let node = if let TyKind :: Path ( QPath :: Resolved ( _, path) ) = ty. kind
185+ && let def:: Res :: Def ( def:: DefKind :: TyParam , did) = path. res
186+ {
187+ tcx. hir ( )
188+ . parent_owner_iter ( arg_hir_id)
189+ . find ( |( _, node) | {
190+ tcx. generics_of ( node. def_id ( ) )
191+ . own_params
192+ . iter ( )
193+ . any ( |param| param. def_id == did)
194+ } )
195+ . unwrap ( )
196+ } else {
197+ tcx. hir ( )
198+ . parent_owner_iter ( arg_hir_id)
199+ . find ( |( _, node) | matches ! ( node, OwnerNode :: Item ( _) ) )
200+ . unwrap ( )
201+ } ;
202+ let item_def_id = node. 0 . def_id ;
191203 let ty = ItemCtxt :: new ( tcx, item_def_id) . lower_ty ( hir_ty) ;
192204
193205 // Iterate through the generics of the projection to find the one that corresponds to
0 commit comments