diff --git a/rust/ql/lib/codeql/rust/internal/PathResolution.qll b/rust/ql/lib/codeql/rust/internal/PathResolution.qll index ca05b0fba7d1..6f2783b9eb6c 100644 --- a/rust/ql/lib/codeql/rust/internal/PathResolution.qll +++ b/rust/ql/lib/codeql/rust/internal/PathResolution.qll @@ -524,7 +524,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 { @@ -532,9 +532,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() } @@ -733,7 +733,7 @@ class TraitItemNode extends ImplOrTraitItemNode instanceof Trait { } pragma[nomagic] - ItemNode resolveABound() { result = resolvePathFull(this.getABoundPath()) } + ItemNode resolveABound() { result = resolvePath(this.getABoundPath()) } override AssocItemNode getAnAssocItem() { result = super.getAssocItemList().getAnAssocItem() } @@ -872,7 +872,7 @@ class TypeParamItemNode extends ItemNode 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: @@ -1285,14 +1285,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 @@ -1301,30 +1296,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() } @@ -1370,7 +1344,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()) } diff --git a/rust/ql/lib/codeql/rust/internal/TypeInference.qll b/rust/ql/lib/codeql/rust/internal/TypeInference.qll index fcacfd5d3dad..a8e429f6f7bf 100644 --- a/rust/ql/lib/codeql/rust/internal/TypeInference.qll +++ b/rust/ql/lib/codeql/rust/internal/TypeInference.qll @@ -1231,9 +1231,10 @@ private module Cached { f = any(Impl impl | impl.hasTrait()).(ImplItemNode).getAnAssocItem() } - private Function resolveMethodCallTargetFrom(MethodCall mc, boolean fromSource) { + /** Gets a method that the method call `mc` resolves to, if any. */ + cached + Function resolveMethodCallTarget(MethodCall mc) { result = inferMethodCallTarget(mc) and - (if result.fromSource() then fromSource = true else fromSource = false) and ( // prioritize inherent implementation methods first isInherentImplFunction(result) @@ -1255,17 +1256,6 @@ private module Cached { ) } - /** Gets a method that the method call `mc` resolves to, if any. */ - cached - Function resolveMethodCallTarget(MethodCall mc) { - // Functions in source code also gets extracted as library code, due to - // this duplication we prioritize functions from source code. - result = resolveMethodCallTargetFrom(mc, true) - or - not exists(resolveMethodCallTargetFrom(mc, true)) and - result = resolveMethodCallTargetFrom(mc, false) - } - pragma[inline] private Type inferRootTypeDeref(AstNode n) { result = inferType(n) and