Skip to content

Commit 2394f2f

Browse files
committed
Rust: Fix bug in path resolution library
1 parent 795ba25 commit 2394f2f

File tree

3 files changed

+11
-20
lines changed

3 files changed

+11
-20
lines changed

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ abstract class ImplOrTraitItemNode extends ItemNode {
284284
/** Gets a `Self` path that refers to this item. */
285285
Path getASelfPath() {
286286
isUnqualifiedSelfPath(result) and
287-
this = unqualifiedPathLookup(result)
287+
this = unqualifiedPathLookup(result, _)
288288
}
289289

290290
/** Gets an associated item belonging to this trait or `impl` block. */
@@ -680,8 +680,8 @@ private ItemNode getASuccessor(ItemNode pred, string name, Namespace ns) {
680680
}
681681

682682
pragma[nomagic]
683-
private ItemNode unqualifiedPathLookup(RelevantPath path) {
684-
exists(ItemNode encl, Namespace ns, string name |
683+
private ItemNode unqualifiedPathLookup(RelevantPath path, Namespace ns) {
684+
exists(ItemNode encl, string name |
685685
unqualifiedPathLookup(path, name, ns, encl) and
686686
result = getASuccessor(encl, name, ns)
687687
)
@@ -691,9 +691,9 @@ pragma[nomagic]
691691
private predicate isUnqualifiedSelfPath(RelevantPath path) { path.isUnqualified("Self") }
692692

693693
pragma[nomagic]
694-
private ItemNode resolvePath0(RelevantPath path) {
694+
private ItemNode resolvePath0(RelevantPath path, Namespace ns) {
695695
exists(ItemNode res |
696-
res = unqualifiedPathLookup(path) and
696+
res = unqualifiedPathLookup(path, ns) and
697697
if
698698
not any(RelevantPath parent).getQualifier() = path and
699699
isUnqualifiedSelfPath(path) and
@@ -704,10 +704,12 @@ private ItemNode resolvePath0(RelevantPath path) {
704704
or
705705
exists(ItemNode q, string name |
706706
q = resolvePathQualifier(path, name) and
707-
result = q.getASuccessor(name)
707+
result = q.getASuccessor(name) and
708+
ns = result.getNamespace()
708709
)
709710
or
710-
result = resolveUseTreeListItem(_, _, path)
711+
result = resolveUseTreeListItem(_, _, path) and
712+
ns = result.getNamespace()
711713
}
712714

713715
/** Holds if path `p` must be looked up in namespace `n`. */
@@ -743,9 +745,8 @@ private predicate pathUsesNamespace(Path p, Namespace n) {
743745
/** Gets the item that `path` resolves to, if any. */
744746
cached
745747
ItemNode resolvePath(RelevantPath path) {
746-
result = resolvePath0(path) and
747-
(
748-
pathUsesNamespace(path, result.getNamespace())
748+
exists(Namespace ns | result = resolvePath0(path, ns) |
749+
pathUsesNamespace(path, ns)
749750
or
750751
not pathUsesNamespace(path, _)
751752
)

rust/ql/test/library-tests/type-inference/CONSISTENCY/AstConsistency.expected

Lines changed: 0 additions & 5 deletions
This file was deleted.

rust/ql/test/library-tests/type-inference/type-inference.expected

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -424,19 +424,14 @@ resolveType
424424
| main.rs:385:16:385:24 | SelfParam | &T | main.rs:384:5:390:5 | trait MyTrait |
425425
| main.rs:385:16:385:24 | SelfParam | &T.S | main.rs:384:19:384:19 | S |
426426
| main.rs:385:27:385:31 | value | | main.rs:384:19:384:19 | S |
427-
| main.rs:385:27:385:31 | value | | main.rs:411:5:412:13 | struct S |
428427
| main.rs:387:21:387:29 | SelfParam | | file://:0:0:0:0 | & |
429428
| main.rs:387:21:387:29 | SelfParam | &T | main.rs:384:5:390:5 | trait MyTrait |
430429
| main.rs:387:21:387:29 | SelfParam | &T.S | main.rs:384:19:384:19 | S |
431-
| main.rs:387:21:387:29 | SelfParam | &T.S | main.rs:411:5:412:13 | struct S |
432430
| main.rs:387:32:387:36 | value | | main.rs:384:19:384:19 | S |
433-
| main.rs:387:32:387:36 | value | | main.rs:411:5:412:13 | struct S |
434431
| main.rs:388:13:388:16 | self | | file://:0:0:0:0 | & |
435432
| main.rs:388:13:388:16 | self | &T | main.rs:384:5:390:5 | trait MyTrait |
436433
| main.rs:388:13:388:16 | self | &T.S | main.rs:384:19:384:19 | S |
437-
| main.rs:388:13:388:16 | self | &T.S | main.rs:411:5:412:13 | struct S |
438434
| main.rs:388:22:388:26 | value | | main.rs:384:19:384:19 | S |
439-
| main.rs:388:22:388:26 | value | | main.rs:411:5:412:13 | struct S |
440435
| main.rs:393:16:393:24 | SelfParam | | file://:0:0:0:0 | & |
441436
| main.rs:393:16:393:24 | SelfParam | &T | main.rs:378:5:382:5 | enum MyOption |
442437
| main.rs:393:16:393:24 | SelfParam | &T.T | main.rs:392:10:392:10 | T |

0 commit comments

Comments
 (0)