Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 22 additions & 14 deletions rust/ql/lib/codeql/rust/internal/PathResolution.qll
Original file line number Diff line number Diff line change
Expand Up @@ -882,20 +882,24 @@ private predicate hasChild(ItemNode parent, ItemNode child) { child.getImmediate
private predicate rootHasCratePathTc(ItemNode i1, ItemNode i2) =
doublyBoundedFastTC(hasChild/2, isRoot/1, hasCratePath/1)(i1, i2)

pragma[nomagic]
private predicate unqualifiedPathLookup1(RelevantPath p, string name, Namespace ns, ItemNode encl) {
unqualifiedPathLookup(p, name, ns, encl)
or
// For `($)crate`, jump directly to the root module
exists(ItemNode i | p.isCratePath(name, i) |
encl.(ModuleLikeNode).isRoot() and
encl = i
or
rootHasCratePathTc(encl, i)
)
}

pragma[nomagic]
private ItemNode unqualifiedPathLookup(RelevantPath path, Namespace ns) {
exists(ItemNode encl, string name |
result = getASuccessor(encl, pragma[only_bind_into](name), ns)
|
unqualifiedPathLookup(path, name, ns, encl)
or
// For `($)crate`, jump directly to the root module
exists(ItemNode i | path.isCratePath(pragma[only_bind_into](name), i) |
encl.(ModuleLikeNode).isRoot() and
encl = i
or
rootHasCratePathTc(encl, i)
)
result = getASuccessor(encl, name, ns) and
unqualifiedPathLookup1(path, name, ns, encl)
)
}

Expand All @@ -916,8 +920,7 @@ private ItemNode resolvePath0(RelevantPath path, Namespace ns) {
or
exists(ItemNode q, string name |
q = resolvePathQualifier(path, name) and
result = q.getASuccessor(name) and
ns = result.getNamespace()
result = getASuccessor(q, name, ns)
)
or
result = resolveUseTreeListItem(_, _, path) and
Expand Down Expand Up @@ -978,6 +981,11 @@ private ItemNode resolvePathPrivate(
)
}

pragma[nomagic]
private predicate isItemParent(ModuleLikeNode itemParent) {
exists(resolvePathPrivate(_, itemParent, _))
}

/**
* Gets a module that has access to private items defined inside `itemParent`.
*
Expand All @@ -988,7 +996,7 @@ private ItemNode resolvePathPrivate(
*/
pragma[nomagic]
private ModuleLikeNode getAPrivateVisibleModule(ModuleLikeNode itemParent) {
exists(resolvePathPrivate(_, itemParent, _)) and
isItemParent(itemParent) and
result.getImmediateParentModule*() = itemParent
}

Expand Down