From 780e1a365b10027c4bd4adcc939ab32da1d91492 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 8 Jun 2019 18:38:14 +0300 Subject: somewhat better name --- crates/ra_hir/src/resolve.rs | 6 +++++- crates/ra_hir/src/source_binder.rs | 4 ++-- crates/ra_hir/src/ty/infer.rs | 37 ++++++++++++++++++++----------------- crates/ra_hir/src/ty/lower.rs | 4 ++-- 4 files changed, 29 insertions(+), 22 deletions(-) (limited to 'crates/ra_hir/src') diff --git a/crates/ra_hir/src/resolve.rs b/crates/ra_hir/src/resolve.rs index d6956f45e..347bcf27d 100644 --- a/crates/ra_hir/src/resolve.rs +++ b/crates/ra_hir/src/resolve.rs @@ -165,7 +165,11 @@ impl Resolver { /// Returns the fully resolved path if we were able to resolve it. /// otherwise returns `PerNs::none` - pub(crate) fn resolve_path(&self, db: &impl HirDatabase, path: &Path) -> PerNs { + pub(crate) fn resolve_path_without_assoc_items( + &self, + db: &impl HirDatabase, + path: &Path, + ) -> PerNs { // into_fully_resolved() returns the fully resolved path or PerNs::none() otherwise self.resolve_path_segments(db, path).into_fully_resolved() } diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index 410064d45..63ec59314 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs @@ -277,7 +277,7 @@ impl SourceAnalyzer { db: &impl HirDatabase, path: &crate::Path, ) -> PerNs { - self.resolver.resolve_path(db, path) + self.resolver.resolve_path_without_assoc_items(db, path) } pub fn resolve_path(&self, db: &impl HirDatabase, path: &ast::Path) -> Option { @@ -294,7 +294,7 @@ impl SourceAnalyzer { } } let hir_path = crate::Path::from_ast(path)?; - let res = self.resolver.resolve_path(db, &hir_path); + let res = self.resolver.resolve_path_without_assoc_items(db, &hir_path); let res = res.clone().take_types().or_else(|| res.take_values())?; let res = match res { crate::Resolution::Def(it) => PathResolution::Def(it), diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index 6cc5dbc6f..6aa727ea1 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs @@ -610,23 +610,26 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { None => return (Ty::Unknown, None), }; let resolver = &self.resolver; - let typable: Option = match resolver.resolve_path(self.db, &path).take_types() { - Some(Resolution::Def(def)) => def.into(), - Some(Resolution::LocalBinding(..)) => { - // this cannot happen - log::error!("path resolved to local binding in type ns"); - return (Ty::Unknown, None); - } - Some(Resolution::GenericParam(..)) => { - // generic params can't be used in struct literals - return (Ty::Unknown, None); - } - Some(Resolution::SelfType(..)) => { - // FIXME this is allowed in an impl for a struct, handle this - return (Ty::Unknown, None); - } - None => return (Ty::Unknown, None), - }; + let typable: Option = + // FIXME: this should resolve assoc items as well, see this example: + // https://play.rust-lang.org/?gist=087992e9e22495446c01c0d4e2d69521 + match resolver.resolve_path_without_assoc_items(self.db, &path).take_types() { + Some(Resolution::Def(def)) => def.into(), + Some(Resolution::LocalBinding(..)) => { + // this cannot happen + log::error!("path resolved to local binding in type ns"); + return (Ty::Unknown, None); + } + Some(Resolution::GenericParam(..)) => { + // generic params can't be used in struct literals + return (Ty::Unknown, None); + } + Some(Resolution::SelfType(..)) => { + // FIXME this is allowed in an impl for a struct, handle this + return (Ty::Unknown, None); + } + None => return (Ty::Unknown, None), + }; let def = match typable { None => return (Ty::Unknown, None), Some(it) => it, diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs index 71cd72234..26c213a41 100644 --- a/crates/ra_hir/src/ty/lower.rs +++ b/crates/ra_hir/src/ty/lower.rs @@ -65,7 +65,7 @@ impl Ty { pub(crate) fn from_hir_path(db: &impl HirDatabase, resolver: &Resolver, path: &Path) -> Self { // Resolve the path (in type namespace) - let resolution = resolver.resolve_path(db, path).take_types(); + let resolution = resolver.resolve_path_without_assoc_items(db, path).take_types(); let def = match resolution { Some(Resolution::Def(def)) => def, @@ -216,7 +216,7 @@ impl TraitRef { path: &Path, explicit_self_ty: Option, ) -> Option { - let resolved = match resolver.resolve_path(db, &path).take_types()? { + let resolved = match resolver.resolve_path_without_assoc_items(db, &path).take_types()? { Resolution::Def(ModuleDef::Trait(tr)) => tr, _ => return None, }; -- cgit v1.2.3