Skip to content

Commit 3d395dd

Browse files
committed
Address review comments
1 parent c6efc05 commit 3d395dd

File tree

3 files changed

+39
-42
lines changed

3 files changed

+39
-42
lines changed

rust/ql/lib/codeql/rust/elements/internal/GenericArgListImpl.qll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,15 @@ module Impl {
3737

3838
/** Gets a type argument of this list. */
3939
TypeRepr getATypeArg() { result = this.getTypeArg(_) }
40+
41+
/** Gets the associated type argument with the given `name`, if any. */
42+
pragma[nomagic]
43+
TypeRepr getAssocTypeArg(string name) {
44+
exists(AssocTypeArg arg |
45+
arg = this.getAGenericArg() and
46+
result = arg.getTypeRepr() and
47+
name = arg.getIdentifier().getText()
48+
)
49+
}
4050
}
4151
}

rust/ql/lib/codeql/rust/internal/TypeInference.qll

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,7 @@ private module Input2 implements InputSig2 {
112112

113113
class TypeMention = TM::TypeMention;
114114

115-
TypeMention getABaseTypeMention(Type t) {
116-
result =
117-
t.(ImplTraitReturnType).getImplTraitTypeRepr().getTypeBoundList().getABound().getTypeRepr()
118-
}
115+
TypeMention getABaseTypeMention(Type t) { none() }
119116

120117
TypeMention getATypeParameterConstraint(TypeParameter tp) {
121118
result = tp.(TypeParamTypeParameter).getTypeParam().getTypeBoundList().getABound().getTypeRepr()

rust/ql/lib/codeql/rust/internal/TypeMention.qll

Lines changed: 28 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,29 @@ class PathTypeReprMention extends TypeMention instanceof PathTypeRepr {
5656

5757
ItemNode getResolved() { result = resolved }
5858

59+
pragma[nomagic]
60+
private TypeAlias getResolvedTraitAlias(string name) {
61+
exists(TraitItemNode trait |
62+
trait = resolvePath(path) and
63+
result = trait.getAnAssocItem() and
64+
name = result.getName().getText()
65+
)
66+
}
67+
68+
pragma[nomagic]
69+
private TypeRepr getAssocTypeArg(string name) {
70+
result = path.getSegment().getGenericArgList().getAssocTypeArg(name)
71+
}
72+
73+
/** Gets the type argument for the associated type `alias`, if any. */
74+
pragma[nomagic]
75+
private TypeRepr getAnAssocTypeArgument(TypeAlias alias) {
76+
exists(string name |
77+
alias = this.getResolvedTraitAlias(name) and
78+
result = this.getAssocTypeArg(name)
79+
)
80+
}
81+
5982
override TypeMention getTypeArgument(int i) {
6083
result = path.getSegment().getGenericArgList().getTypeArg(i)
6184
or
@@ -96,6 +119,11 @@ class PathTypeReprMention extends TypeMention instanceof PathTypeRepr {
96119
result = alias.getTypeRepr() and
97120
param.getIndex() = i
98121
)
122+
or
123+
exists(TypeAlias alias |
124+
result = this.getAnAssocTypeArgument(alias) and
125+
traitAliasIndex(_, i, alias)
126+
)
99127
}
100128

101129
/**
@@ -150,44 +178,6 @@ class PathTypeReprMention extends TypeMention instanceof PathTypeRepr {
150178
not exists(resolved.(TypeAlias).getTypeRepr()) and
151179
result = super.resolveTypeAt(typePath)
152180
}
153-
154-
pragma[nomagic]
155-
private TypeAlias getResolvedTraitAlias(string name) {
156-
exists(TraitItemNode trait |
157-
trait = resolvePath(path) and
158-
result = trait.getAnAssocItem() and
159-
name = result.getName().getText()
160-
)
161-
}
162-
163-
pragma[nomagic]
164-
private TypeRepr getAssocTypeArg(string name) {
165-
exists(AssocTypeArg arg |
166-
arg = path.getSegment().getGenericArgList().getAGenericArg() and
167-
result = arg.getTypeRepr() and
168-
name = arg.getIdentifier().getText()
169-
)
170-
}
171-
172-
/** Gets the type argument for the associated type `alias`, if any. */
173-
pragma[nomagic]
174-
private TypeRepr getAnAssocTypeArgument(TypeAlias alias) {
175-
exists(string name |
176-
alias = this.getResolvedTraitAlias(name) and
177-
result = this.getAssocTypeArg(name)
178-
)
179-
}
180-
181-
override TypeMention getMentionAt(TypePath tp) {
182-
result = super.getMentionAt(tp)
183-
or
184-
exists(TypeAlias alias, AssociatedTypeTypeParameter attp, TypeMention arg, TypePath suffix |
185-
arg = this.getAnAssocTypeArgument(alias) and
186-
result = arg.getMentionAt(suffix) and
187-
tp = TypePath::cons(attp, suffix) and
188-
attp.getTypeAlias() = alias
189-
)
190-
}
191181
}
192182

193183
class ImplTraitTypeReprMention extends TypeMention instanceof ImplTraitTypeRepr {

0 commit comments

Comments
 (0)