Skip to content

Commit e35d861

Browse files
committed
Rust: Make crate fallback logic more conservative in path resolution library
1 parent b0fa3e7 commit e35d861

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,11 +1529,11 @@ private predicate crateDependencyEdge(SourceFileItemNode file, string name, Crat
15291529
crateDependency(file, name, dep)
15301530
or
15311531
// As a fallback, give all files access to crates that do not conflict with known dependencies
1532-
// and declarations. This is in order to workaround incomplete crate dependency information
1533-
// provided by the extractor, as well as `CrateItemNode.getASourceFile()` being unable to map
1534-
// a given file to its crate (for example, if the file is `mod` imported inside a macro that the
1535-
// extractor is unable to expand).
1536-
name = dep.getName() and
1532+
// and declarations, as long as those crates have a unique name.
1533+
// This is in order to workaround incomplete crate dependency information provided by the extractor,
1534+
// as well as `CrateItemNode.getASourceFile()` being unable to map a given file to its crate (for
1535+
// example, if the file is `mod` imported inside a macro that the extractor is unable to expand).
1536+
dep = unique(CrateItemNode dep0 | name = dep0.getName()) and
15371537
not hasDeclOrDep(file, name)
15381538
}
15391539

@@ -2385,6 +2385,11 @@ private module Debug {
23852385
useImportEdge(use, name, item, kind)
23862386
}
23872387

2388+
predicate debugCrateDependencyEdge(SourceFileItemNode file, string name, CrateItemNode dep) {
2389+
file = getRelevantLocatable() and
2390+
crateDependencyEdge(file, name, dep)
2391+
}
2392+
23882393
ItemNode debugGetASuccessor(ItemNode i, string name, SuccessorKind kind) {
23892394
i = getRelevantLocatable() and
23902395
result = i.getASuccessor(name, kind, _)

0 commit comments

Comments
 (0)