somewhat better name

This commit is contained in:
Aleksey Kladov 2019-06-08 18:38:14 +03:00
parent bb55111c20
commit 780e1a365b
4 changed files with 29 additions and 22 deletions

View file

@ -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<Resolution> {
pub(crate) fn resolve_path_without_assoc_items(
&self,
db: &impl HirDatabase,
path: &Path,
) -> PerNs<Resolution> {
// into_fully_resolved() returns the fully resolved path or PerNs::none() otherwise
self.resolve_path_segments(db, path).into_fully_resolved()
}

View file

@ -277,7 +277,7 @@ impl SourceAnalyzer {
db: &impl HirDatabase,
path: &crate::Path,
) -> PerNs<crate::Resolution> {
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<PathResolution> {
@ -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),

View file

@ -610,23 +610,26 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
None => return (Ty::Unknown, None),
};
let resolver = &self.resolver;
let typable: Option<TypableDef> = 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<TypableDef> =
// 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,

View file

@ -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<Ty>,
) -> Option<Self> {
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,
};