Skip to content

Commit 54f2945

Browse files
committed
Address review comments
1 parent 2ebb619 commit 54f2945

File tree

5 files changed

+41
-46
lines changed

5 files changed

+41
-46
lines changed

rust/ql/.generated.list

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/ql/.gitattributes

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// generated by codegen, remove this comment if you wish to edit this file
21
/**
32
* This module provides a hand-modifiable wrapper around the generated class `AssocTypeArg`.
43
*
@@ -12,6 +11,7 @@ private import codeql.rust.elements.internal.generated.AssocTypeArg
1211
* be referenced directly.
1312
*/
1413
module Impl {
14+
// the following QLdoc is generated: if you need to edit it, do it in the schema file
1515
/**
1616
* An associated type argument in a path.
1717
*
@@ -26,5 +26,12 @@ module Impl {
2626
* }
2727
* ```
2828
*/
29-
class AssocTypeArg extends Generated::AssocTypeArg { }
29+
class AssocTypeArg extends Generated::AssocTypeArg {
30+
/** Gets the type representation for the associated type argument `name`. */
31+
pragma[nomagic]
32+
TypeRepr getTypeRepr(string name) {
33+
result = this.getTypeRepr() and
34+
name = this.getIdentifier().getText()
35+
}
36+
}
3037
}

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: 31 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,32 @@ 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+
exists(AssocTypeArg arg |
71+
arg = path.getSegment().getGenericArgList().getAGenericArg() and
72+
result = arg.getTypeRepr(name)
73+
)
74+
}
75+
76+
/** Gets the type argument for the associated type `alias`, if any. */
77+
pragma[nomagic]
78+
private TypeRepr getAnAssocTypeArgument(TypeAlias alias) {
79+
exists(string name |
80+
alias = this.getResolvedTraitAlias(name) and
81+
result = this.getAssocTypeArg(name)
82+
)
83+
}
84+
5985
override TypeMention getTypeArgument(int i) {
6086
result = path.getSegment().getGenericArgList().getTypeArg(i)
6187
or
@@ -96,6 +122,11 @@ class PathTypeReprMention extends TypeMention instanceof PathTypeRepr {
96122
result = alias.getTypeRepr() and
97123
param.getIndex() = i
98124
)
125+
or
126+
exists(TypeAlias alias |
127+
result = this.getAnAssocTypeArgument(alias) and
128+
traitAliasIndex(_, i, alias)
129+
)
99130
}
100131

101132
/**
@@ -150,44 +181,6 @@ class PathTypeReprMention extends TypeMention instanceof PathTypeRepr {
150181
not exists(resolved.(TypeAlias).getTypeRepr()) and
151182
result = super.resolveTypeAt(typePath)
152183
}
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-
}
191184
}
192185

193186
class ImplTraitTypeReprMention extends TypeMention instanceof ImplTraitTypeRepr {

0 commit comments

Comments
 (0)