Skip to content

Commit c58319d

Browse files
committed
Rust: Fallback crate resolution
1 parent db50642 commit c58319d

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ abstract class ItemNode extends Locatable {
173173
crateDefEdge(this, name, result, kind)
174174
or
175175
crateDependencyEdge(this, name, result) and
176+
not declares(this, TTypeNamespace(), name) and
176177
kind.isInternal()
177178
or
178179
externCrateEdge(this, name, result) and
@@ -1138,6 +1139,11 @@ private class BuiltinSourceFile extends SourceFileItemNode {
11381139
pragma[nomagic]
11391140
private predicate crateDependencyEdge(SourceFileItemNode file, string name, CrateItemNode dep) {
11401141
exists(CrateItemNode c | dep = c.(Crate).getDependency(name) | file = c.getASourceFile())
1142+
or
1143+
// All files _should_ belong to a crate, but for those where we cannot identify the crate,
1144+
// give access to all crates as a fallback.
1145+
not file = any(Crate c).getASourceFile() and
1146+
name = dep.getName()
11411147
}
11421148

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

0 commit comments

Comments
 (0)