Skip to content

Commit b5b6f06

Browse files
committed
Rust: Fix bad join
``` Evaluated relational algebra for predicate _PathResolution::CrateItemNode.getName/0#dispred#91b4dd6b_PathResolution::SourceFileItemNode#bd8f490__#antijoin_rhs@e84aee8k with tuple counts: 35406180 ~0% {3} r1 = JOIN PathResolution::SourceFileItemNode#bd8f4905 WITH `PathResolution::CrateItemNode.getName/0#dispred#91b4dd6b` CARTESIAN PRODUCT OUTPUT Lhs.0, Rhs.1, Rhs.0 8455 ~2% {4} | JOIN WITH `PathResolution::declaresDirectly/3#7d0350fb_021#join_rhs` ON FIRST 2 OUTPUT Rhs.2, Lhs.0, Lhs.2, Lhs.1 3259 ~0% {3} | JOIN WITH num#PathResolution::TTypeNamespace#4897e416 ON FIRST 1 OUTPUT Lhs.1, Lhs.2, Lhs.3 return r1 ```
1 parent b2cc01c commit b5b6f06

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,6 +1321,12 @@ private predicate crateDependency(SourceFileItemNode file, string name, CrateIte
13211321
exists(CrateItemNode c | dep = c.(Crate).getDependency(name) | file = c.getASourceFile())
13221322
}
13231323

1324+
pragma[nomagic]
1325+
private predicate hasDeclOrDep(SourceFileItemNode file, string name) {
1326+
declaresDirectly(file, TTypeNamespace(), name) or
1327+
crateDependency(file, name, _)
1328+
}
1329+
13241330
/**
13251331
* Holds if `file` depends on crate `dep` named `name`.
13261332
*/
@@ -1334,8 +1340,7 @@ private predicate crateDependencyEdge(SourceFileItemNode file, string name, Crat
13341340
// a given file to its crate (for example, if the file is `mod` imported inside a macro that the
13351341
// extractor is unable to expand).
13361342
name = dep.getName() and
1337-
not declaresDirectly(file, TTypeNamespace(), name) and
1338-
not crateDependency(file, name, _)
1343+
not hasDeclOrDep(file, name)
13391344
}
13401345

13411346
private predicate useTreeDeclares(UseTree tree, string name) {

0 commit comments

Comments
 (0)