Skip to content

Commit abc63f2

Browse files
committed
sdf
1 parent c75974a commit abc63f2

File tree

2 files changed

+180
-146
lines changed

2 files changed

+180
-146
lines changed

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ class FunctionType extends TFunctionType {
186186
* For functions belonging to a `trait`, we use the type of the trait itself instead
187187
* of the implicit `Self` type parameter, as otherwise any type will match.
188188
*
189-
* Calls will use `substituteLookupTraits` to map receiver types to the relevant
189+
* Calls should use `substituteLookupTraits` to map receiver types to the relevant
190190
* traits when matching.
191191
*/
192192
Type getTypeAt(TypePath path) {
@@ -219,3 +219,25 @@ class FunctionType extends TFunctionType {
219219

220220
Location getLocation() { result = this.getReportingNode().getLocation() }
221221
}
222+
223+
private Trait getALookupTrait(Type t) {
224+
result = t.(TypeParamTypeParameter).getTypeParam().(TypeParamItemNode).resolveABound()
225+
or
226+
result = t.(SelfTypeParameter).getTrait()
227+
or
228+
result = t.(ImplTraitType).getImplTraitTypeRepr().(ImplTraitTypeReprItemNode).resolveABound()
229+
or
230+
result = t.(DynTraitType).getTrait()
231+
}
232+
233+
/**
234+
* Gets the type obtained by substituting in relevant traits in which to do function
235+
* lookup, or `t` itself when no such trait exist.
236+
*/
237+
bindingset[t]
238+
Type substituteLookupTraits(Type t) {
239+
not exists(getALookupTrait(t)) and
240+
result = t
241+
or
242+
result = TTrait(getALookupTrait(t))
243+
}

0 commit comments

Comments
 (0)