@@ -15,7 +15,7 @@ abstract class TypeMention extends AstNode {
1515
1616 /** Gets the sub mention at `path`. */
1717 pragma [ nomagic]
18- private TypeMention getMentionAt ( TypePath path ) {
18+ TypeMention getMentionAt ( TypePath path ) {
1919 path .isEmpty ( ) and
2020 result = this
2121 or
@@ -44,6 +44,19 @@ class TypeReprMention extends TypeMention, TypeRepr {
4444 result = this .( PathTypeRepr ) .getPath ( ) .( PathMention ) .getTypeArgument ( i )
4545 }
4646
47+ /**
48+ * Gets an [`impl Trait`][1] bound. For example, if this mention is
49+ * `impl A + B` then this predicate returns `A` and `B`.
50+ *
51+ * [1] https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
52+ */
53+ private PathMention getAnImplTraitBound ( ) {
54+ exists ( TypeBoundList tbl |
55+ tbl = this .( ImplTraitTypeRepr ) .getTypeBoundList ( ) and
56+ result = tbl .getABound ( ) .getTypeRepr ( ) .( PathTypeRepr ) .getPath ( )
57+ )
58+ }
59+
4760 override Type resolveType ( ) {
4861 this instanceof ArrayTypeRepr and
4962 result = TArrayType ( )
@@ -52,12 +65,17 @@ class TypeReprMention extends TypeMention, TypeRepr {
5265 result = TRefType ( )
5366 or
5467 result = this .( PathTypeRepr ) .getPath ( ) .( PathMention ) .resolveType ( )
68+ or
69+ result = this .getAnImplTraitBound ( ) .resolveType ( )
5570 }
5671
5772 override Type resolveTypeAt ( TypePath path ) {
5873 result = this .( PathTypeRepr ) .getPath ( ) .( PathMention ) .resolveTypeAt ( path )
5974 or
75+ result = this .getAnImplTraitBound ( ) .resolveTypeAt ( path )
76+ or
6077 not exists ( this .( PathTypeRepr ) .getPath ( ) ) and
78+ not exists ( this .getAnImplTraitBound ( ) ) and
6179 result = super .resolveTypeAt ( path )
6280 }
6381}
@@ -71,6 +89,30 @@ abstract class PathMention extends TypeMention, Path {
7189 override TypeMention getTypeArgument ( int i ) {
7290 result = this .getSegment ( ) .getGenericArgList ( ) .getTypeArg ( i )
7391 }
92+
93+ /** Gets the type argument for the associated type `alias`, if any. */
94+ pragma [ nomagic]
95+ private TypeRepr getAnAssocTypeArgument ( TypeAlias alias ) {
96+ exists ( TraitItemNode trait , string name , AssocTypeArg arg |
97+ alias = trait .getAnAssocItem ( ) and
98+ name = alias .getName ( ) .getText ( ) and
99+ trait = resolvePath ( this ) and
100+ arg = this .getSegment ( ) .getGenericArgList ( ) .getAGenericArg ( ) and
101+ result = arg .getTypeRepr ( ) and
102+ name = arg .getIdentifier ( ) .getText ( )
103+ )
104+ }
105+
106+ override TypeMention getMentionAt ( TypePath path ) {
107+ result = super .getMentionAt ( path )
108+ or
109+ exists ( TypeAlias alias , AssociatedTypeTypeParameter tp , TypeMention arg , TypePath suffix |
110+ arg = this .getAnAssocTypeArgument ( alias ) and
111+ result = arg .getMentionAt ( suffix ) and
112+ path = TypePath:: cons ( tp , suffix ) and
113+ tp .getTypeAlias ( ) = alias
114+ )
115+ }
74116}
75117
76118class NonAliasPathMention extends PathMention {
0 commit comments