Skip to content

Commit 9323f1a

Browse files
authored
Merge pull request #19250 from hvitved/rust/fix-bad-joins
Rust: Fix bad joins
2 parents b6053e3 + 95add2f commit 9323f1a

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

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

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -882,20 +882,24 @@ private predicate hasChild(ItemNode parent, ItemNode child) { child.getImmediate
882882
private predicate rootHasCratePathTc(ItemNode i1, ItemNode i2) =
883883
doublyBoundedFastTC(hasChild/2, isRoot/1, hasCratePath/1)(i1, i2)
884884

885+
pragma[nomagic]
886+
private predicate unqualifiedPathLookup1(RelevantPath p, string name, Namespace ns, ItemNode encl) {
887+
unqualifiedPathLookup(p, name, ns, encl)
888+
or
889+
// For `($)crate`, jump directly to the root module
890+
exists(ItemNode i | p.isCratePath(name, i) |
891+
encl.(ModuleLikeNode).isRoot() and
892+
encl = i
893+
or
894+
rootHasCratePathTc(encl, i)
895+
)
896+
}
897+
885898
pragma[nomagic]
886899
private ItemNode unqualifiedPathLookup(RelevantPath path, Namespace ns) {
887900
exists(ItemNode encl, string name |
888-
result = getASuccessor(encl, pragma[only_bind_into](name), ns)
889-
|
890-
unqualifiedPathLookup(path, name, ns, encl)
891-
or
892-
// For `($)crate`, jump directly to the root module
893-
exists(ItemNode i | path.isCratePath(pragma[only_bind_into](name), i) |
894-
encl.(ModuleLikeNode).isRoot() and
895-
encl = i
896-
or
897-
rootHasCratePathTc(encl, i)
898-
)
901+
result = getASuccessor(encl, name, ns) and
902+
unqualifiedPathLookup1(path, name, ns, encl)
899903
)
900904
}
901905

@@ -916,8 +920,7 @@ private ItemNode resolvePath0(RelevantPath path, Namespace ns) {
916920
or
917921
exists(ItemNode q, string name |
918922
q = resolvePathQualifier(path, name) and
919-
result = q.getASuccessor(name) and
920-
ns = result.getNamespace()
923+
result = getASuccessor(q, name, ns)
921924
)
922925
or
923926
result = resolveUseTreeListItem(_, _, path) and
@@ -978,6 +981,11 @@ private ItemNode resolvePathPrivate(
978981
)
979982
}
980983

984+
pragma[nomagic]
985+
private predicate isItemParent(ModuleLikeNode itemParent) {
986+
exists(resolvePathPrivate(_, itemParent, _))
987+
}
988+
981989
/**
982990
* Gets a module that has access to private items defined inside `itemParent`.
983991
*
@@ -988,7 +996,7 @@ private ItemNode resolvePathPrivate(
988996
*/
989997
pragma[nomagic]
990998
private ModuleLikeNode getAPrivateVisibleModule(ModuleLikeNode itemParent) {
991-
exists(resolvePathPrivate(_, itemParent, _)) and
999+
isItemParent(itemParent) and
9921000
result.getImmediateParentModule*() = itemParent
9931001
}
9941002

0 commit comments

Comments
 (0)