Rust: Special-case Self::AssocType in path resolution

This commit is contained in:
Tom Hvitved
2025-11-26 11:47:27 +01:00
parent 0d46dc0461
commit 7e5131891c
5 changed files with 12 additions and 11 deletions

View File

@@ -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))
)
)
}

View File

@@ -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 |

View File

@@ -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
}
@@ -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
}
}
}

View File

@@ -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 |
@@ -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 |

View File

@@ -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 |