Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions rust/ql/lib/codeql/rust/internal/PathResolution.qll
Original file line number Diff line number Diff line change
Expand Up @@ -1897,6 +1897,16 @@ private ItemNode resolvePathCandQualified(PathExt qualifier, ItemNode q, PathExt
q = resolvePathCandQualifier(qualifier, path, name) and
result = getASuccessor(q, name, ns, kind, useOpt) and
checkQualifiedVisibility(path, result, kind, useOpt)
|
// Special case for `Self::AssocType`; this always refers to the associated
// type in the enclosing `impl` block, if available.
forall(ImplItemNode impl, TypeAliasItemNode alias |
qualifier = impl.getASelfPath() and alias = result
|
alias = impl.getAnAssocItem()
or
not exists(impl.getAssocItem(name).(TypeAliasItemNode))
)
Comment thread
hvitved marked this conversation as resolved.
Outdated
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,3 @@ multipleCallTargets
| main.rs:369:9:371:16 | ...::f(...) |
| main.rs:450:9:454:16 | ...::f(...) |
| main.rs:455:9:459:16 | ...::f(...) |
multiplePathResolutions
| main.rs:492:20:492:34 | ...::AssocType |
| main.rs:504:20:504:34 | ...::AssocType |
4 changes: 2 additions & 2 deletions rust/ql/test/library-tests/path-resolution/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ mod m16 {
; // S2Trait3AssocType

fn f(&self) {
let x: Self::AssocType = 42; // $ item=S2Trait3AssocType $ SPURIOUS: item=S2Trait4AssocType
let x: Self::AssocType = 42; // $ item=S2Trait3AssocType
} // S2asTrait3::f
}

Expand All @@ -501,7 +501,7 @@ mod m16 {
fn g(&self) {
Self::f(&self); // $ item=S2asTrait3::f
S2::f(&self); // $ item=S2asTrait3::f
let x: Self::AssocType = true; // $ item=S2Trait4AssocType $ SPURIOUS: item=S2Trait3AssocType
let x: Self::AssocType = true; // $ item=S2Trait4AssocType
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ resolvePath
| main.rs:488:26:488:28 | i32 | {EXTERNAL LOCATION} | struct i32 |
| main.rs:492:20:492:23 | Self | main.rs:484:5:484:14 | struct S2 |
| main.rs:492:20:492:34 | ...::AssocType | main.rs:487:26:489:9 | type AssocType |
| main.rs:492:20:492:34 | ...::AssocType | main.rs:497:26:499:9 | type AssocType |
| main.rs:497:10:497:15 | Trait4 | main.rs:478:5:482:5 | trait Trait4 |
| main.rs:497:21:497:22 | S2 | main.rs:484:5:484:14 | struct S2 |
| main.rs:498:26:498:29 | bool | {EXTERNAL LOCATION} | struct bool |
Expand All @@ -278,7 +277,6 @@ resolvePath
| main.rs:503:13:503:14 | S2 | main.rs:484:5:484:14 | struct S2 |
| main.rs:503:13:503:17 | ...::f | main.rs:489:11:493:9 | fn f |
| main.rs:504:20:504:23 | Self | main.rs:484:5:484:14 | struct S2 |
| main.rs:504:20:504:34 | ...::AssocType | main.rs:487:26:489:9 | type AssocType |
| main.rs:504:20:504:34 | ...::AssocType | main.rs:497:26:499:9 | type AssocType |
| main.rs:521:14:521:16 | Foo | main.rs:511:9:513:9 | trait Foo |
| main.rs:521:22:521:22 | X | main.rs:519:9:519:21 | struct X |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,3 @@ multipleCallTargets
| main.rs:2642:13:2642:31 | ...::from(...) |
| main.rs:2643:13:2643:31 | ...::from(...) |
| main.rs:2644:13:2644:31 | ...::from(...) |
multiplePathResolutions
| main.rs:2463:41:2463:52 | ...::Output |
| main.rs:2472:38:2472:49 | ...::Output |
| main.rs:2484:42:2484:53 | ...::Output |