From 444f6caababc3335b1ed51d08eeedac106fd8077 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Thu, 1 Apr 2021 18:01:18 +0200 Subject: Resolve associated types --- crates/hir/src/semantics.rs | 6 ++++-- crates/hir/src/source_analyzer.rs | 19 +++++++++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) (limited to 'crates/hir/src') diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs index d3caeef4e..3bf722d2a 100644 --- a/crates/hir/src/semantics.rs +++ b/crates/hir/src/semantics.rs @@ -76,9 +76,11 @@ impl PathResolution { pub fn assoc_type_shorthand_candidates( &self, db: &dyn HirDatabase, - mut cb: impl FnMut(TypeAlias) -> Option, + mut cb: impl FnMut(&Name, TypeAlias) -> Option, ) -> Option { - associated_type_shorthand_candidates(db, self.in_type_ns()?, |_, _, id| cb(id.into())) + associated_type_shorthand_candidates(db, self.in_type_ns()?, |name, _, id| { + cb(name, id.into()) + }) } } diff --git a/crates/hir/src/source_analyzer.rs b/crates/hir/src/source_analyzer.rs index 37d162b32..8423dd101 100644 --- a/crates/hir/src/source_analyzer.rs +++ b/crates/hir/src/source_analyzer.rs @@ -466,7 +466,8 @@ fn resolve_hir_path_( prefer_value_ns: bool, ) -> Option { let types = || { - resolver.resolve_path_in_type_ns_fully(db.upcast(), path.mod_path()).map(|ty| match ty { + let (ty, remaining) = resolver.resolve_path_in_type_ns(db.upcast(), path.mod_path())?; + let res = match ty { TypeNs::SelfType(it) => PathResolution::SelfType(it.into()), TypeNs::GenericParam(id) => PathResolution::TypeParam(TypeParam { id }), TypeNs::AdtSelfType(it) | TypeNs::AdtId(it) => { @@ -476,7 +477,21 @@ fn resolve_hir_path_( TypeNs::TypeAliasId(it) => PathResolution::Def(TypeAlias::from(it).into()), TypeNs::BuiltinType(it) => PathResolution::Def(BuiltinType::from(it).into()), TypeNs::TraitId(it) => PathResolution::Def(Trait::from(it).into()), - }) + }; + match remaining { + Some(1) => { + let unresolved = path.segments().get(1)?; + res.assoc_type_shorthand_candidates(db, |name, alias| { + (name == unresolved.name).then(|| alias) + }) + .map(TypeAlias::from) + .map(Into::into) + .map(PathResolution::Def) + } + // ambiguous + Some(_) => None, + None => Some(res), + } }; let body_owner = resolver.body_owner(); -- cgit v1.2.3