Skip to content

Commit 119397d

Browse files
committed
Rust: Remove source vs library deduplication logic
1 parent 16690cc commit 119397d

File tree

2 files changed

+11
-47
lines changed

2 files changed

+11
-47
lines changed

rust/ql/lib/codeql/rust/elements/internal/MethodCallExprImpl.qll

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ module Impl {
3131
* ```
3232
*/
3333
class MethodCallExpr extends Generated::MethodCallExpr {
34-
private Function getStaticTargetFrom(boolean fromSource) {
34+
override Function getStaticTarget() {
3535
result = resolveMethodCallExpr(this) and
36-
(if result.fromSource() then fromSource = true else fromSource = false) and
3736
(
3837
// prioritize inherent implementation methods first
3938
isInherentImplFunction(result)
@@ -55,15 +54,6 @@ module Impl {
5554
)
5655
}
5756

58-
override Function getStaticTarget() {
59-
// Functions in source code also gets extracted as library code, due to
60-
// this duplication we prioritize functions from source code.
61-
result = this.getStaticTargetFrom(true)
62-
or
63-
not exists(this.getStaticTargetFrom(true)) and
64-
result = this.getStaticTargetFrom(false)
65-
}
66-
6757
private string toStringPart(int index) {
6858
index = 0 and
6959
result = this.getReceiver().toAbbreviatedString()

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

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -524,17 +524,17 @@ abstract class ImplOrTraitItemNode extends ItemNode {
524524

525525
pragma[nomagic]
526526
private TypeParamItemNode resolveTypeParamPathTypeRepr(PathTypeRepr ptr) {
527-
result = resolvePathFull(ptr.getPath())
527+
result = resolvePath(ptr.getPath())
528528
}
529529

530530
class ImplItemNode extends ImplOrTraitItemNode instanceof Impl {
531531
Path getSelfPath() { result = super.getSelfTy().(PathTypeRepr).getPath() }
532532

533533
Path getTraitPath() { result = super.getTrait().(PathTypeRepr).getPath() }
534534

535-
ItemNode resolveSelfTy() { result = resolvePathFull(this.getSelfPath()) }
535+
ItemNode resolveSelfTy() { result = resolvePath(this.getSelfPath()) }
536536

537-
TraitItemNode resolveTraitTy() { result = resolvePathFull(this.getTraitPath()) }
537+
TraitItemNode resolveTraitTy() { result = resolvePath(this.getTraitPath()) }
538538

539539
override AssocItemNode getAnAssocItem() { result = super.getAssocItemList().getAnAssocItem() }
540540

@@ -733,7 +733,7 @@ class TraitItemNode extends ImplOrTraitItemNode instanceof Trait {
733733
}
734734

735735
pragma[nomagic]
736-
ItemNode resolveABound() { result = resolvePathFull(this.getABoundPath()) }
736+
ItemNode resolveABound() { result = resolvePath(this.getABoundPath()) }
737737

738738
override AssocItemNode getAnAssocItem() { result = super.getAssocItemList().getAnAssocItem() }
739739

@@ -872,7 +872,7 @@ class TypeParamItemNode extends ItemNode instanceof TypeParam {
872872
}
873873

874874
pragma[nomagic]
875-
ItemNode resolveABound() { result = resolvePathFull(this.getABoundPath()) }
875+
ItemNode resolveABound() { result = resolvePath(this.getABoundPath()) }
876876

877877
/**
878878
* Holds if this type parameter has a trait bound. Examples:
@@ -1285,14 +1285,9 @@ private predicate pathUsesNamespace(Path p, Namespace n) {
12851285
)
12861286
}
12871287

1288-
/**
1289-
* Gets the item that `path` resolves to, if any.
1290-
*
1291-
* Whenever `path` can resolve to both a function in source code and in library
1292-
* code, both are included
1293-
*/
1294-
pragma[nomagic]
1295-
private ItemNode resolvePathFull(RelevantPath path) {
1288+
/** Gets the item that `path` resolves to, if any. */
1289+
cached
1290+
ItemNode resolvePath(RelevantPath path) {
12961291
exists(Namespace ns | result = resolvePath0(path, ns) |
12971292
pathUsesNamespace(path, ns)
12981293
or
@@ -1301,30 +1296,9 @@ private ItemNode resolvePathFull(RelevantPath path) {
13011296
)
13021297
}
13031298

1304-
pragma[nomagic]
1305-
private predicate resolvesSourceFunction(RelevantPath path) {
1306-
resolvePathFull(path).(Function).fromSource()
1307-
}
1308-
1309-
/** Gets the item that `path` resolves to, if any. */
1310-
cached
1311-
ItemNode resolvePath(RelevantPath path) {
1312-
result = resolvePathFull(path) and
1313-
(
1314-
// when a function exists in both source code and in library code, it is because
1315-
// we also extracted the source code as library code, and hence we only want
1316-
// the function from source code
1317-
result.fromSource()
1318-
or
1319-
not result instanceof Function
1320-
or
1321-
not resolvesSourceFunction(path)
1322-
)
1323-
}
1324-
13251299
pragma[nomagic]
13261300
private ItemNode resolvePathQualifier(RelevantPath path, string name) {
1327-
result = resolvePathFull(path.getQualifier()) and
1301+
result = resolvePath(path.getQualifier()) and
13281302
name = path.getText()
13291303
}
13301304

@@ -1370,7 +1344,7 @@ private ItemNode resolveUseTreeListItemQualifier(
13701344
pragma[nomagic]
13711345
private ItemNode resolveUseTreeListItem(Use use, UseTree tree) {
13721346
tree = use.getUseTree() and
1373-
result = resolvePathFull(tree.getPath())
1347+
result = resolvePath(tree.getPath())
13741348
or
13751349
result = resolveUseTreeListItem(use, tree, tree.getPath())
13761350
}

0 commit comments

Comments
 (0)