@@ -52,10 +52,21 @@ newtype TType =
5252 TAssociatedTypeTypeParameter ( TypeAlias t ) { any ( TraitItemNode trait ) .getAnAssocItem ( ) = t } or
5353 TArrayTypeParameter ( ) or
5454 TDynTraitTypeParameter ( AstNode n ) { dynTraitTypeParameter ( _, n ) } or
55+ TImplTraitTypeParameter ( ImplTraitTypeRepr implTrait , TypeParam tp ) {
56+ implTraitTypeParam ( implTrait , _, tp )
57+ } or
5558 TRefTypeParameter ( ) or
5659 TSelfTypeParameter ( Trait t ) or
5760 TSliceTypeParameter ( )
5861
62+ predicate implTraitTypeParam ( ImplTraitTypeRepr implTrait , int i , TypeParam tp ) {
63+ implTrait .isInReturnPos ( ) and
64+ tp = implTrait .getFunction ( ) .getGenericParamList ( ) .getTypeParam ( i ) and
65+ // Only include type parameters of the function that occur inside the impl
66+ // trait type.
67+ exists ( Path path | path .getParentNode * ( ) = implTrait and resolvePath ( path ) = tp )
68+ }
69+
5970/**
6071 * A type without type arguments.
6172 *
@@ -263,7 +274,12 @@ class ImplTraitType extends Type, TImplTraitType {
263274
264275 override TupleField getTupleField ( int i ) { none ( ) }
265276
266- override TypeParameter getTypeParameter ( int i ) { none ( ) }
277+ override TypeParameter getTypeParameter ( int i ) {
278+ exists ( TypeParam tp |
279+ implTraitTypeParam ( impl , i , tp ) and
280+ result = TImplTraitTypeParameter ( impl , tp )
281+ )
282+ }
267283
268284 override string toString ( ) { result = impl .toString ( ) }
269285
@@ -302,7 +318,7 @@ class DynTraitType extends Type, TDynTraitType {
302318class ImplTraitReturnType extends ImplTraitType {
303319 private Function function ;
304320
305- ImplTraitReturnType ( ) { impl = function . getRetType ( ) . getTypeRepr ( ) }
321+ ImplTraitReturnType ( ) { impl . isInReturnPos ( ) and function = impl . getFunction ( ) }
306322
307323 override Function getFunction ( ) { result = function }
308324}
@@ -456,6 +472,21 @@ class DynTraitTypeParameter extends TypeParameter, TDynTraitTypeParameter {
456472 override Location getLocation ( ) { result = n .getLocation ( ) }
457473}
458474
475+ class ImplTraitTypeParameter extends TypeParameter , TImplTraitTypeParameter {
476+ private TypeParam typeParam ;
477+ private ImplTraitTypeRepr implTrait ;
478+
479+ ImplTraitTypeParameter ( ) { this = TImplTraitTypeParameter ( implTrait , typeParam ) }
480+
481+ TypeParam getTypeParam ( ) { result = typeParam }
482+
483+ ImplTraitTypeRepr getImplTraitTypeRepr ( ) { result = implTrait }
484+
485+ override string toString ( ) { result = "impl(" + typeParam .toString ( ) + ")" }
486+
487+ override Location getLocation ( ) { result = typeParam .getLocation ( ) }
488+ }
489+
459490/** An implicit reference type parameter. */
460491class RefTypeParameter extends TypeParameter , TRefTypeParameter {
461492 override string toString ( ) { result = "&T" }
@@ -569,5 +600,7 @@ final class SelfTypeBoundTypeAbstraction extends TypeAbstraction, Name {
569600}
570601
571602final class ImplTraitTypeReprAbstraction extends TypeAbstraction , ImplTraitTypeRepr {
572- override TypeParameter getATypeParameter ( ) { none ( ) }
603+ override TypeParameter getATypeParameter ( ) {
604+ implTraitTypeParam ( this , _, result .( TypeParamTypeParameter ) .getTypeParam ( ) )
605+ }
573606}
0 commit comments