Skip to content

Commit 0e8c137

Browse files
committed
Rust: Only include paths as type mentions when they're used as such
On databend this changes the number of `PathTypeMention`s from 3,777,464 to 3,330,024. Not a huge difference, but there's also downstream predicates that are reduced as well.
1 parent 620d228 commit 0e8c137

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,24 @@ class SliceTypeReprMention extends TypeMention instanceof SliceTypeRepr {
5050
}
5151
}
5252

53+
/** Holds if `path` is used as a type mention during type inference. */
54+
predicate relevantPathTypeMention(Path path) {
55+
path =
56+
[
57+
any(PathTypeRepr r).getPath(),
58+
any(StructExpr s).getPath().getQualifier*(),
59+
any(CallExpr ce).getFunction().(PathExpr).getPath().getQualifier*(),
60+
any(StructPat p).getPath(),
61+
any(TupleStructPat p).getPath()
62+
]
63+
}
64+
5365
class PathTypeMention extends TypeMention, Path {
5466
TypeItemNode resolved;
5567

5668
PathTypeMention() {
57-
resolved = resolvePath(this)
58-
or
59-
resolved = resolvePath(this).(Variant).getEnum()
69+
relevantPathTypeMention(this) and
70+
resolved = [resolvePath(this), resolvePath(this).(Variant).getEnum().(TypeItemNode)]
6071
}
6172

6273
TypeItemNode getResolved() { result = resolved }

0 commit comments

Comments
 (0)