Skip to content

Commit 6919095

Browse files
committed
Rust: Crate graph extraction workarounds
1 parent c11ed6d commit 6919095

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

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

+32-3
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,16 @@ abstract private class AssocItemNode extends ItemNode, AssocItem {
323323
private class ConstItemNode extends AssocItemNode instanceof Const {
324324
override string getName() { result = Const.super.getName().getText() }
325325

326-
override predicate hasImplementation() { super.hasBody() }
326+
override predicate hasImplementation() {
327+
super.hasBody()
328+
or
329+
// for trait items from library code, we do not currently know if they
330+
// have default implementations or not, so we assume they do
331+
exists(TraitItemNode t |
332+
this = t.getAnAssocItem() and
333+
not this.fromSource()
334+
)
335+
}
327336

328337
override Namespace getNamespace() { result.isValue() }
329338

@@ -359,7 +368,16 @@ private class VariantItemNode extends ItemNode instanceof Variant {
359368
class FunctionItemNode extends AssocItemNode instanceof Function {
360369
override string getName() { result = Function.super.getName().getText() }
361370

362-
override predicate hasImplementation() { super.hasBody() }
371+
override predicate hasImplementation() {
372+
super.hasBody()
373+
or
374+
// for trait items from library code, we do not currently know if they
375+
// have default implementations or not, so we assume they do
376+
exists(TraitItemNode t |
377+
this = t.getAnAssocItem() and
378+
not this.fromSource()
379+
)
380+
}
363381

364382
override Namespace getNamespace() { result.isValue() }
365383

@@ -854,6 +872,12 @@ class RelevantPath extends Path {
854872
this.getQualifier().(RelevantPath).isCratePath("$crate", _) and
855873
this.getText() = name
856874
}
875+
876+
// TODO: Remove once the crate graph extractor generates publicly visible paths
877+
predicate requiresExtractorWorkaround() {
878+
not this.fromSource() and
879+
this = any(RelevantPath p).getQualifier()
880+
}
857881
}
858882

859883
/**
@@ -998,6 +1022,7 @@ pragma[nomagic]
9981022
private ItemNode resolvePathPrivate(
9991023
RelevantPath path, ModuleLikeNode itemParent, ModuleLikeNode pathParent
10001024
) {
1025+
not path.requiresExtractorWorkaround() and
10011026
result = resolvePath1(path) and
10021027
itemParent = result.getImmediateParentModule() and
10031028
not result.isPublic() and
@@ -1031,7 +1056,11 @@ private ModuleLikeNode getAPrivateVisibleModule(ModuleLikeNode itemParent) {
10311056
cached
10321057
ItemNode resolvePath(RelevantPath path) {
10331058
result = resolvePath1(path) and
1034-
result.isPublic()
1059+
(
1060+
result.isPublic()
1061+
or
1062+
path.requiresExtractorWorkaround()
1063+
)
10351064
or
10361065
exists(ModuleLikeNode itemParent, ModuleLikeNode pathParent |
10371066
result = resolvePathPrivate(path, itemParent, pathParent) and

0 commit comments

Comments
 (0)