Skip to content

Commit a6491df

Browse files
committed
Rust: Fix bug in path resolution library
1 parent 3af7e9b commit a6491df

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
@@ -396,19 +396,14 @@ resolveType
396396
| main.rs:379:16:379:24 | SelfParam | 0 | main.rs:378:5:384:5 | trait MyTrait |
397397
| main.rs:379:16:379:24 | SelfParam | 0.0 | main.rs:378:19:378:19 | S |
398398
| main.rs:379:27:379:31 | value | | main.rs:378:19:378:19 | S |
399-
| main.rs:379:27:379:31 | value | | main.rs:405:5:406:13 | struct S |
400399
| main.rs:381:21:381:29 | SelfParam | | file://:0:0:0:0 | & |
401400
| main.rs:381:21:381:29 | SelfParam | 0 | main.rs:378:5:384:5 | trait MyTrait |
402401
| main.rs:381:21:381:29 | SelfParam | 0.0 | main.rs:378:19:378:19 | S |
403-
| main.rs:381:21:381:29 | SelfParam | 0.0 | main.rs:405:5:406:13 | struct S |
404402
| main.rs:381:32:381:36 | value | | main.rs:378:19:378:19 | S |
405-
| main.rs:381:32:381:36 | value | | main.rs:405:5:406:13 | struct S |
406403
| main.rs:382:13:382:16 | self | | file://:0:0:0:0 | & |
407404
| main.rs:382:13:382:16 | self | 0 | main.rs:378:5:384:5 | trait MyTrait |
408405
| main.rs:382:13:382:16 | self | 0.0 | main.rs:378:19:378:19 | S |
409-
| main.rs:382:13:382:16 | self | 0.0 | main.rs:405:5:406:13 | struct S |
410406
| main.rs:382:22:382:26 | value | | main.rs:378:19:378:19 | S |
411-
| main.rs:382:22:382:26 | value | | main.rs:405:5:406:13 | struct S |
412407
| main.rs:387:16:387:24 | SelfParam | | file://:0:0:0:0 | & |
413408
| main.rs:387:16:387:24 | SelfParam | 0 | main.rs:372:5:376:5 | enum MyOption |
414409
| main.rs:387:16:387:24 | SelfParam | 0.0 | main.rs:386:10:386:10 | T |

0 commit comments

Comments
 (0)