From 379c913ce3d8084c3dd8e6bbaf66e5dcd552dc80 Mon Sep 17 00:00:00 2001 From: Tom Hvitved Date: Mon, 26 May 2025 09:35:55 +0200 Subject: [PATCH] Rust: Remove source vs library deduplication logic --- .../codeql/rust/internal/PathResolution.qll | 50 +++++-------------- 1 file changed, 12 insertions(+), 38 deletions(-) diff --git a/rust/ql/lib/codeql/rust/internal/PathResolution.qll b/rust/ql/lib/codeql/rust/internal/PathResolution.qll index 3c0033ab7be3..0d4e8e163be1 100644 --- a/rust/ql/lib/codeql/rust/internal/PathResolution.qll +++ b/rust/ql/lib/codeql/rust/internal/PathResolution.qll @@ -561,7 +561,7 @@ abstract class ImplOrTraitItemNode extends ItemNode { pragma[nomagic] private TypeParamItemNode resolveTypeParamPathTypeRepr(PathTypeRepr ptr) { - result = resolvePathFull(ptr.getPath()) + result = resolvePath(ptr.getPath()) } class ImplItemNode extends ImplOrTraitItemNode instanceof Impl { @@ -569,9 +569,9 @@ class ImplItemNode extends ImplOrTraitItemNode instanceof Impl { Path getTraitPath() { result = super.getTrait().(PathTypeRepr).getPath() } - ItemNode resolveSelfTy() { result = resolvePathFull(this.getSelfPath()) } + ItemNode resolveSelfTy() { result = resolvePath(this.getSelfPath()) } - TraitItemNode resolveTraitTy() { result = resolvePathFull(this.getTraitPath()) } + TraitItemNode resolveTraitTy() { result = resolvePath(this.getTraitPath()) } override AssocItemNode getAnAssocItem() { result = super.getAssocItemList().getAnAssocItem() } @@ -665,7 +665,7 @@ private class ImplTraitTypeReprItemNode extends ItemNode instanceof ImplTraitTyp } pragma[nomagic] - ItemNode resolveABound() { result = resolvePathFull(this.getABoundPath()) } + ItemNode resolveABound() { result = resolvePath(this.getABoundPath()) } override string getName() { result = "(impl trait)" } @@ -795,7 +795,7 @@ class TraitItemNode extends ImplOrTraitItemNode, TypeItemNode instanceof Trait { } pragma[nomagic] - ItemNode resolveABound() { result = resolvePathFull(this.getABoundPath()) } + ItemNode resolveABound() { result = resolvePath(this.getABoundPath()) } override AssocItemNode getAnAssocItem() { result = super.getAssocItemList().getAnAssocItem() } @@ -847,7 +847,7 @@ class TraitItemNode extends ImplOrTraitItemNode, TypeItemNode instanceof Trait { class TypeAliasItemNode extends TypeItemNode, AssocItemNode instanceof TypeAlias { pragma[nomagic] - ItemNode resolveAlias() { result = resolvePathFull(super.getTypeRepr().(PathTypeRepr).getPath()) } + ItemNode resolveAlias() { result = resolvePath(super.getTypeRepr().(PathTypeRepr).getPath()) } override string getName() { result = TypeAlias.super.getName().getText() } @@ -941,7 +941,7 @@ class TypeParamItemNode extends TypeItemNode instanceof TypeParam { } pragma[nomagic] - ItemNode resolveABound() { result = resolvePathFull(this.getABoundPath()) } + ItemNode resolveABound() { result = resolvePath(this.getABoundPath()) } /** * Holds if this type parameter has a trait bound. Examples: @@ -1369,14 +1369,9 @@ private predicate pathUsesNamespace(Path p, Namespace n) { ) } -/** - * Gets the item that `path` resolves to, if any. - * - * Whenever `path` can resolve to both a function in source code and in library - * code, both are included - */ -pragma[nomagic] -private ItemNode resolvePathFull(RelevantPath path) { +/** Gets the item that `path` resolves to, if any. */ +cached +ItemNode resolvePath(RelevantPath path) { exists(Namespace ns | result = resolvePath0(path, ns) | pathUsesNamespace(path, ns) or @@ -1385,30 +1380,9 @@ private ItemNode resolvePathFull(RelevantPath path) { ) } -pragma[nomagic] -private predicate resolvesSourceFunction(RelevantPath path) { - resolvePathFull(path).(Function).fromSource() -} - -/** Gets the item that `path` resolves to, if any. */ -cached -ItemNode resolvePath(RelevantPath path) { - result = resolvePathFull(path) and - ( - // when a function exists in both source code and in library code, it is because - // we also extracted the source code as library code, and hence we only want - // the function from source code - result.fromSource() - or - not result instanceof Function - or - not resolvesSourceFunction(path) - ) -} - pragma[nomagic] private ItemNode resolvePathQualifier(RelevantPath path, string name) { - result = resolvePathFull(path.getQualifier()) and + result = resolvePath(path.getQualifier()) and name = path.getText() } @@ -1454,7 +1428,7 @@ private ItemNode resolveUseTreeListItemQualifier( pragma[nomagic] private ItemNode resolveUseTreeListItem(Use use, UseTree tree) { tree = use.getUseTree() and - result = resolvePathFull(tree.getPath()) + result = resolvePath(tree.getPath()) or result = resolveUseTreeListItem(use, tree, tree.getPath()) }