Skip to content

Commit 6fc9369

Browse files
committed
Rust: Take where clauses into account in path resolution
1 parent 68690b4 commit 6fc9369

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -542,9 +542,21 @@ private class BlockExprItemNode extends ItemNode instanceof BlockExpr {
542542
}
543543

544544
private class TypeParamItemNode extends ItemNode instanceof TypeParam {
545+
private WherePred getAWherePred() {
546+
exists(ItemNode declaringItem |
547+
this = resolveTypeParamPathTypeRepr(result.getTypeRepr()) and
548+
result = declaringItem.getADescendant() and
549+
this = declaringItem.getADescendant()
550+
)
551+
}
552+
545553
pragma[nomagic]
546554
Path getABoundPath() {
547-
result = super.getTypeBoundList().getABound().getTypeRepr().(PathTypeRepr).getPath()
555+
exists(TypeBoundList tbl | result = tbl.getABound().getTypeRepr().(PathTypeRepr).getPath() |
556+
tbl = super.getTypeBoundList()
557+
or
558+
tbl = this.getAWherePred().getTypeBoundList()
559+
)
548560
}
549561

550562
ItemNode resolveABound() { result = resolvePath(this.getABoundPath()) }
@@ -564,11 +576,7 @@ private class TypeParamItemNode extends ItemNode instanceof TypeParam {
564576
predicate hasTraitBound() {
565577
exists(this.getABoundPath())
566578
or
567-
exists(ItemNode declaringItem, WherePred wp |
568-
this = resolveTypeParamPathTypeRepr(wp.getTypeRepr()) and
569-
wp = declaringItem.getADescendant() and
570-
this = declaringItem.getADescendant()
571-
)
579+
exists(this.getAWherePred())
572580
}
573581

574582
/**

0 commit comments

Comments
 (0)