Skip to content

Commit 651e162

Browse files
committed
Rust: Fix bad join
``` Evaluated relational algebra for predicate _Crate::Crate.getSourceFile/0#dispred#e7adf9d7_Crate::Generated::Crate.getName/0#dispred#f4d3b3bf_Pa__#join_rhs@5a04a7t0 with tuple counts: 34471980 ~0% {3} r1 = JOIN `PathResolution::isSourceFile/1#803de032` WITH `Crate::Crate.getSourceFile/0#dispred#e7adf9d7` CARTESIAN PRODUCT OUTPUT Rhs.0, Lhs.0, Rhs.1 34471980 ~37% {4} | JOIN WITH `Crate::Generated::Crate.getName/0#dispred#f4d3b3bf` ON FIRST 1 OUTPUT Lhs.1, Lhs.2, Rhs.1, _ {3} | REWRITE WITH NOT [Tmp.3 := "std", TEST InOut.2 != Tmp.3, Tmp.3 := "core", TEST InOut.2 != Tmp.3] KEEPING 3 93420 ~91% {3} | SCAN OUTPUT In.1, _, In.0 93420 ~87% {3} | REWRITE WITH Out.1 := "prelude" return r1 ```
1 parent 65bf76e commit 651e162

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,6 +1464,18 @@ private predicate externCrateEdge(ExternCrateItemNode ec, string name, CrateItem
14641464
)
14651465
}
14661466

1467+
pragma[nomagic]
1468+
private predicate preludeItem(string name, ItemNode i) {
1469+
exists(Crate stdOrCore, ModuleLikeNode mod, ModuleItemNode prelude, ModuleItemNode rust |
1470+
stdOrCore.getName() = ["std", "core"] and
1471+
mod = stdOrCore.getSourceFile() and
1472+
prelude = mod.getASuccessorRec("prelude") and
1473+
rust = prelude.getASuccessorRec(["rust_2015", "rust_2018", "rust_2021", "rust_2024"]) and
1474+
i = rust.getASuccessorRec(name) and
1475+
not i instanceof Use
1476+
)
1477+
}
1478+
14671479
/**
14681480
* Holds if `i` is available inside `f` because it is reexported in
14691481
* [the `core` prelude][1] or [the `std` prelude][2].
@@ -1476,15 +1488,8 @@ private predicate externCrateEdge(ExternCrateItemNode ec, string name, CrateItem
14761488
*/
14771489
pragma[nomagic]
14781490
private predicate preludeEdge(SourceFile f, string name, ItemNode i) {
1479-
not declares(f, _, name) and
1480-
exists(Crate stdOrCore, ModuleLikeNode mod, ModuleItemNode prelude, ModuleItemNode rust |
1481-
stdOrCore.getName() = ["std", "core"] and
1482-
mod = stdOrCore.getSourceFile() and
1483-
prelude = mod.getASuccessorRec("prelude") and
1484-
rust = prelude.getASuccessorRec(["rust_2015", "rust_2018", "rust_2021", "rust_2024"]) and
1485-
i = rust.getASuccessorRec(name) and
1486-
not i instanceof Use
1487-
)
1491+
preludeItem(name, i) and
1492+
not declares(f, _, name)
14881493
}
14891494

14901495
pragma[nomagic]

0 commit comments

Comments
 (0)