Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir/src/attrs.rs')
-rw-r--r--crates/hir/src/attrs.rs62
1 files changed, 32 insertions, 30 deletions
diff --git a/crates/hir/src/attrs.rs b/crates/hir/src/attrs.rs
index 4e45b5a250..b1c478d1bf 100644
--- a/crates/hir/src/attrs.rs
+++ b/crates/hir/src/attrs.rs
@@ -3,14 +3,17 @@
use std::ops::ControlFlow;
use hir_def::{
+ AssocItemId, AttrDefId, ModuleDefId,
attr::AttrsWithOwner,
+ expr_store::path::Path,
item_scope::ItemInNs,
- path::{ModPath, Path},
per_ns::Namespace,
resolver::{HasResolver, Resolver, TypeNs},
- AssocItemId, AttrDefId, ModuleDefId,
};
-use hir_expand::{mod_path::PathKind, name::Name};
+use hir_expand::{
+ mod_path::{ModPath, PathKind},
+ name::Name,
+};
use hir_ty::{db::HirDatabase, method_resolution};
use crate::{
@@ -30,7 +33,7 @@ macro_rules! impl_has_attrs {
impl HasAttrs for $def {
fn attrs(self, db: &dyn HirDatabase) -> AttrsWithOwner {
let def = AttrDefId::$def_id(self.into());
- AttrsWithOwner::new(db.upcast(), def)
+ AttrsWithOwner::new(db, def)
}
fn attr_id(self) -> AttrDefId {
AttrDefId::$def_id(self.into())
@@ -92,7 +95,7 @@ impl HasAttrs for AssocItem {
impl HasAttrs for crate::Crate {
fn attrs(self, db: &dyn HirDatabase) -> AttrsWithOwner {
let def = AttrDefId::ModuleId(self.root_module().id);
- AttrsWithOwner::new(db.upcast(), def)
+ AttrsWithOwner::new(db, def)
}
fn attr_id(self) -> AttrDefId {
AttrDefId::ModuleId(self.root_module().id)
@@ -116,27 +119,27 @@ fn resolve_doc_path_on_(
ns: Option<Namespace>,
) -> Option<DocLinkDef> {
let resolver = match attr_id {
- AttrDefId::ModuleId(it) => it.resolver(db.upcast()),
- AttrDefId::FieldId(it) => it.parent.resolver(db.upcast()),
- AttrDefId::AdtId(it) => it.resolver(db.upcast()),
- AttrDefId::FunctionId(it) => it.resolver(db.upcast()),
- AttrDefId::EnumVariantId(it) => it.resolver(db.upcast()),
- AttrDefId::StaticId(it) => it.resolver(db.upcast()),
- AttrDefId::ConstId(it) => it.resolver(db.upcast()),
- AttrDefId::TraitId(it) => it.resolver(db.upcast()),
- AttrDefId::TraitAliasId(it) => it.resolver(db.upcast()),
- AttrDefId::TypeAliasId(it) => it.resolver(db.upcast()),
- AttrDefId::ImplId(it) => it.resolver(db.upcast()),
- AttrDefId::ExternBlockId(it) => it.resolver(db.upcast()),
- AttrDefId::UseId(it) => it.resolver(db.upcast()),
- AttrDefId::MacroId(it) => it.resolver(db.upcast()),
- AttrDefId::ExternCrateId(it) => it.resolver(db.upcast()),
+ AttrDefId::ModuleId(it) => it.resolver(db),
+ AttrDefId::FieldId(it) => it.parent.resolver(db),
+ AttrDefId::AdtId(it) => it.resolver(db),
+ AttrDefId::FunctionId(it) => it.resolver(db),
+ AttrDefId::EnumVariantId(it) => it.resolver(db),
+ AttrDefId::StaticId(it) => it.resolver(db),
+ AttrDefId::ConstId(it) => it.resolver(db),
+ AttrDefId::TraitId(it) => it.resolver(db),
+ AttrDefId::TraitAliasId(it) => it.resolver(db),
+ AttrDefId::TypeAliasId(it) => it.resolver(db),
+ AttrDefId::ImplId(it) => it.resolver(db),
+ AttrDefId::ExternBlockId(it) => it.resolver(db),
+ AttrDefId::UseId(it) => it.resolver(db),
+ AttrDefId::MacroId(it) => it.resolver(db),
+ AttrDefId::ExternCrateId(it) => it.resolver(db),
AttrDefId::GenericParamId(_) => return None,
};
let mut modpath = doc_modpath_from_str(link)?;
- let resolved = resolver.resolve_module_path_in_items(db.upcast(), &modpath);
+ let resolved = resolver.resolve_module_path_in_items(db, &modpath);
if resolved.is_none() {
let last_name = modpath.pop_segment()?;
resolve_assoc_or_field(db, resolver, modpath, last_name, ns)
@@ -165,7 +168,7 @@ fn resolve_assoc_or_field(
let path = Path::from_known_path_with_no_generic(path);
// FIXME: This does not handle `Self` on trait definitions, which we should resolve to the
// trait itself.
- let base_def = resolver.resolve_path_in_type_ns_fully(db.upcast(), &path)?;
+ let base_def = resolver.resolve_path_in_type_ns_fully(db, &path)?;
let ty = match base_def {
TypeNs::SelfType(id) => Impl::from(id).self_ty(db),
@@ -194,7 +197,7 @@ fn resolve_assoc_or_field(
// Doc paths in this context may only resolve to an item of this trait
// (i.e. no items of its supertraits), so we need to handle them here
// independently of others.
- return db.trait_data(id).items.iter().find(|it| it.0 == name).map(|(_, assoc_id)| {
+ return db.trait_items(id).items.iter().find(|it| it.0 == name).map(|(_, assoc_id)| {
let def = match *assoc_id {
AssocItemId::FunctionId(it) => ModuleDef::Function(it.into()),
AssocItemId::ConstId(it) => ModuleDef::Const(it.into()),
@@ -207,6 +210,9 @@ fn resolve_assoc_or_field(
// XXX: Do these get resolved?
return None;
}
+ TypeNs::ModuleId(_) => {
+ return None;
+ }
};
// Resolve inherent items first, then trait items, then fields.
@@ -252,7 +258,7 @@ fn resolve_impl_trait_item(
let environment = resolver
.generic_def()
.map_or_else(|| crate::TraitEnvironment::empty(krate.id), |d| db.trait_environment(d));
- let traits_in_scope = resolver.traits_in_scope(db.upcast());
+ let traits_in_scope = resolver.traits_in_scope(db);
let mut result = None;
@@ -260,7 +266,7 @@ fn resolve_impl_trait_item(
// attributes here. Use path resolution directly instead.
//
// FIXME: resolve type aliases (which are not yielded by iterate_path_candidates)
- let _ = method_resolution::iterate_path_candidates(
+ _ = method_resolution::iterate_path_candidates(
&canonical,
db,
environment,
@@ -273,11 +279,7 @@ fn resolve_impl_trait_item(
// disambiguation) so we just pick the first one we find as well.
result = as_module_def_if_namespace_matches(assoc_item_id.into(), ns);
- if result.is_some() {
- ControlFlow::Break(())
- } else {
- ControlFlow::Continue(())
- }
+ if result.is_some() { ControlFlow::Break(()) } else { ControlFlow::Continue(()) }
},
);