mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 04:19:13 +00:00
Fix assoc type shorthand from method bounds
In code like this: ```rust impl<T> Option<T> { fn as_deref(&self) -> T::Target where T: Deref {} } ``` when trying to resolve the associated type `T::Target`, we were only looking at the bounds on the impl (where the type parameter is defined), but the method can add additional bounds that can also be used to refer to associated types. Hence, when resolving such an associated type, it's not enough to just know the type parameter T, we also need to know exactly where we are currently. This fixes #11364 (beta apparently switched some bounds around).
This commit is contained in:
parent
9cb6e3a190
commit
4ed5fe1554
9 changed files with 107 additions and 67 deletions
|
@ -619,9 +619,15 @@ fn resolve_hir_path_(
|
|||
TypeNs::TraitId(it) => PathResolution::Def(Trait::from(it).into()),
|
||||
};
|
||||
match unresolved {
|
||||
Some(unresolved) => res
|
||||
.assoc_type_shorthand_candidates(db, |name, alias| {
|
||||
(name == unresolved.name).then(|| alias)
|
||||
Some(unresolved) => resolver
|
||||
.generic_def()
|
||||
.and_then(|def| {
|
||||
hir_ty::associated_type_shorthand_candidates(
|
||||
db,
|
||||
def,
|
||||
res.in_type_ns()?,
|
||||
|name, _, id| (name == unresolved.name).then(|| id),
|
||||
)
|
||||
})
|
||||
.map(TypeAlias::from)
|
||||
.map(Into::into)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue