Deduplicate some code
This commit is contained in:
parent
bb0de88f24
commit
2ebf0c87c2
22 changed files with 299 additions and 234 deletions
|
@ -356,7 +356,6 @@ impl AttrsWithOwner {
|
|||
AttrDefId::FieldId(it) => {
|
||||
return db.fields_attrs(it.parent)[it.local_id].clone();
|
||||
}
|
||||
// FIXME: DRY this up
|
||||
AttrDefId::EnumVariantId(it) => {
|
||||
let id = it.lookup(db).id;
|
||||
let tree = id.item_tree(db);
|
||||
|
|
|
@ -9,12 +9,16 @@ use hir_expand::{attrs::collect_attrs, HirFileId};
|
|||
|
||||
use crate::{
|
||||
db::DefDatabase,
|
||||
dyn_map::{keys, DynMap},
|
||||
dyn_map::{
|
||||
keys::{self, Key},
|
||||
DynMap,
|
||||
},
|
||||
item_scope::ItemScope,
|
||||
item_tree::ItemTreeModItemNode,
|
||||
nameres::DefMap,
|
||||
src::{HasChildSource, HasSource},
|
||||
AdtId, AssocItemId, DefWithBodyId, EnumId, ExternCrateId, FieldId, ImplId, Lookup, MacroId,
|
||||
ModuleDefId, ModuleId, TraitId, UseId, VariantId,
|
||||
AdtId, AssocItemId, AssocItemLoc, DefWithBodyId, EnumId, FieldId, ImplId, ItemLoc, Lookup,
|
||||
MacroId, ModuleDefId, ModuleId, TraitId, VariantId,
|
||||
};
|
||||
|
||||
pub trait ChildBySource {
|
||||
|
@ -58,22 +62,11 @@ impl ChildBySource for ImplId {
|
|||
fn add_assoc_item(db: &dyn DefDatabase, res: &mut DynMap, file_id: HirFileId, item: AssocItemId) {
|
||||
match item {
|
||||
AssocItemId::FunctionId(func) => {
|
||||
let loc = func.lookup(db);
|
||||
if loc.id.file_id() == file_id {
|
||||
res[keys::FUNCTION].insert(loc.source(db).value, func)
|
||||
}
|
||||
}
|
||||
AssocItemId::ConstId(konst) => {
|
||||
let loc = konst.lookup(db);
|
||||
if loc.id.file_id() == file_id {
|
||||
res[keys::CONST].insert(loc.source(db).value, konst)
|
||||
}
|
||||
insert_assoc_item_loc(db, res, file_id, func, keys::FUNCTION)
|
||||
}
|
||||
AssocItemId::ConstId(konst) => insert_assoc_item_loc(db, res, file_id, konst, keys::CONST),
|
||||
AssocItemId::TypeAliasId(ty) => {
|
||||
let loc = ty.lookup(db);
|
||||
if loc.id.file_id() == file_id {
|
||||
res[keys::TYPE_ALIAS].insert(loc.source(db).value, ty)
|
||||
}
|
||||
insert_assoc_item_loc(db, res, file_id, ty, keys::TYPE_ALIAS)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -89,15 +82,12 @@ impl ChildBySource for ModuleId {
|
|||
impl ChildBySource for ItemScope {
|
||||
fn child_by_source_to(&self, db: &dyn DefDatabase, res: &mut DynMap, file_id: HirFileId) {
|
||||
self.declarations().for_each(|item| add_module_def(db, res, file_id, item));
|
||||
self.impls().for_each(|imp| add_impl(db, res, file_id, imp));
|
||||
self.extern_crate_decls().for_each(|ext| add_extern_crate(db, res, file_id, ext));
|
||||
self.use_decls().for_each(|ext| add_use(db, res, file_id, ext));
|
||||
self.unnamed_consts(db).for_each(|konst| {
|
||||
let loc = konst.lookup(db);
|
||||
if loc.id.file_id() == file_id {
|
||||
res[keys::CONST].insert(loc.source(db).value, konst);
|
||||
}
|
||||
});
|
||||
self.impls().for_each(|imp| insert_item_loc(db, res, file_id, imp, keys::IMPL));
|
||||
self.extern_crate_decls()
|
||||
.for_each(|ext| insert_item_loc(db, res, file_id, ext, keys::EXTERN_CRATE));
|
||||
self.use_decls().for_each(|ext| insert_item_loc(db, res, file_id, ext, keys::USE));
|
||||
self.unnamed_consts(db)
|
||||
.for_each(|konst| insert_assoc_item_loc(db, res, file_id, konst, keys::CONST));
|
||||
self.attr_macro_invocs().filter(|(id, _)| id.file_id == file_id).for_each(
|
||||
|(ast_id, call_id)| {
|
||||
res[keys::ATTR_MACRO_CALL].insert(ast_id.to_node(db.upcast()), call_id);
|
||||
|
@ -141,16 +131,26 @@ impl ChildBySource for ItemScope {
|
|||
}};
|
||||
}
|
||||
match item {
|
||||
ModuleDefId::FunctionId(id) => insert!(map[keys::FUNCTION].insert(id)),
|
||||
ModuleDefId::ConstId(id) => insert!(map[keys::CONST].insert(id)),
|
||||
ModuleDefId::StaticId(id) => insert!(map[keys::STATIC].insert(id)),
|
||||
ModuleDefId::TypeAliasId(id) => insert!(map[keys::TYPE_ALIAS].insert(id)),
|
||||
ModuleDefId::TraitId(id) => insert!(map[keys::TRAIT].insert(id)),
|
||||
ModuleDefId::TraitAliasId(id) => insert!(map[keys::TRAIT_ALIAS].insert(id)),
|
||||
ModuleDefId::FunctionId(id) => {
|
||||
insert_assoc_item_loc(db, map, file_id, id, keys::FUNCTION)
|
||||
}
|
||||
ModuleDefId::ConstId(id) => {
|
||||
insert_assoc_item_loc(db, map, file_id, id, keys::CONST)
|
||||
}
|
||||
ModuleDefId::TypeAliasId(id) => {
|
||||
insert_assoc_item_loc(db, map, file_id, id, keys::TYPE_ALIAS)
|
||||
}
|
||||
ModuleDefId::StaticId(id) => {
|
||||
insert_assoc_item_loc(db, map, file_id, id, keys::STATIC)
|
||||
}
|
||||
ModuleDefId::TraitId(id) => insert_item_loc(db, map, file_id, id, keys::TRAIT),
|
||||
ModuleDefId::TraitAliasId(id) => {
|
||||
insert_item_loc(db, map, file_id, id, keys::TRAIT_ALIAS)
|
||||
}
|
||||
ModuleDefId::AdtId(adt) => match adt {
|
||||
AdtId::StructId(id) => insert!(map[keys::STRUCT].insert(id)),
|
||||
AdtId::UnionId(id) => insert!(map[keys::UNION].insert(id)),
|
||||
AdtId::EnumId(id) => insert!(map[keys::ENUM].insert(id)),
|
||||
AdtId::StructId(id) => insert_item_loc(db, map, file_id, id, keys::STRUCT),
|
||||
AdtId::UnionId(id) => insert_item_loc(db, map, file_id, id, keys::UNION),
|
||||
AdtId::EnumId(id) => insert_item_loc(db, map, file_id, id, keys::ENUM),
|
||||
},
|
||||
ModuleDefId::MacroId(id) => match id {
|
||||
MacroId::Macro2Id(id) => insert!(map[keys::MACRO2].insert(id)),
|
||||
|
@ -162,29 +162,6 @@ impl ChildBySource for ItemScope {
|
|||
| ModuleDefId::BuiltinType(_) => (),
|
||||
}
|
||||
}
|
||||
fn add_impl(db: &dyn DefDatabase, map: &mut DynMap, file_id: HirFileId, imp: ImplId) {
|
||||
let loc = imp.lookup(db);
|
||||
if loc.id.file_id() == file_id {
|
||||
map[keys::IMPL].insert(loc.source(db).value, imp)
|
||||
}
|
||||
}
|
||||
fn add_extern_crate(
|
||||
db: &dyn DefDatabase,
|
||||
map: &mut DynMap,
|
||||
file_id: HirFileId,
|
||||
ext: ExternCrateId,
|
||||
) {
|
||||
let loc = ext.lookup(db);
|
||||
if loc.id.file_id() == file_id {
|
||||
map[keys::EXTERN_CRATE].insert(loc.source(db).value, ext)
|
||||
}
|
||||
}
|
||||
fn add_use(db: &dyn DefDatabase, map: &mut DynMap, file_id: HirFileId, ext: UseId) {
|
||||
let loc = ext.lookup(db);
|
||||
if loc.id.file_id() == file_id {
|
||||
map[keys::USE].insert(loc.source(db).value, ext)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -237,3 +214,37 @@ impl ChildBySource for DefWithBodyId {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn insert_item_loc<ID, N>(
|
||||
db: &dyn DefDatabase,
|
||||
res: &mut DynMap,
|
||||
file_id: HirFileId,
|
||||
id: ID,
|
||||
key: Key<N::Source, ID>,
|
||||
) where
|
||||
ID: for<'db> Lookup<Database<'db> = dyn DefDatabase + 'db, Data = ItemLoc<N>> + 'static,
|
||||
N: ItemTreeModItemNode,
|
||||
N::Source: 'static,
|
||||
{
|
||||
let loc = id.lookup(db);
|
||||
if loc.id.file_id() == file_id {
|
||||
res[key].insert(loc.source(db).value, id)
|
||||
}
|
||||
}
|
||||
|
||||
fn insert_assoc_item_loc<ID, N>(
|
||||
db: &dyn DefDatabase,
|
||||
res: &mut DynMap,
|
||||
file_id: HirFileId,
|
||||
id: ID,
|
||||
key: Key<N::Source, ID>,
|
||||
) where
|
||||
ID: for<'db> Lookup<Database<'db> = dyn DefDatabase + 'db, Data = AssocItemLoc<N>> + 'static,
|
||||
N: ItemTreeModItemNode,
|
||||
N::Source: 'static,
|
||||
{
|
||||
let loc = id.lookup(db);
|
||||
if loc.id.file_id() == file_id {
|
||||
res[key].insert(loc.source(db).value, id)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,13 +21,13 @@ use crate::{
|
|||
db::DefDatabase,
|
||||
dyn_map::{keys, DynMap},
|
||||
expander::Expander,
|
||||
item_tree::ItemTree,
|
||||
item_tree::{ItemTree, ItemTreeModItemNode},
|
||||
lower::LowerCtx,
|
||||
nameres::{DefMap, MacroSubNs},
|
||||
src::{HasChildSource, HasSource},
|
||||
type_ref::{ConstRef, LifetimeRef, TypeBound, TypeRef},
|
||||
AdtId, ConstParamId, GenericDefId, HasModule, LifetimeParamId, LocalLifetimeParamId,
|
||||
LocalTypeOrConstParamId, Lookup, TypeOrConstParamId, TypeParamId,
|
||||
AdtId, AssocItemLoc, ConstParamId, GenericDefId, HasModule, ItemLoc, LifetimeParamId,
|
||||
LocalLifetimeParamId, LocalTypeOrConstParamId, Lookup, TypeOrConstParamId, TypeParamId,
|
||||
};
|
||||
|
||||
/// Data about a generic type parameter (to a function, struct, impl, ...).
|
||||
|
@ -509,47 +509,36 @@ impl GenericParams {
|
|||
}
|
||||
|
||||
fn file_id_and_params_of(
|
||||
def: GenericDefId,
|
||||
db: &dyn DefDatabase,
|
||||
def: GenericDefId,
|
||||
) -> (HirFileId, Option<ast::GenericParamList>) {
|
||||
match def {
|
||||
GenericDefId::FunctionId(it) => {
|
||||
let src = it.lookup(db).source(db);
|
||||
(src.file_id, src.value.generic_param_list())
|
||||
}
|
||||
GenericDefId::AdtId(AdtId::StructId(it)) => {
|
||||
let src = it.lookup(db).source(db);
|
||||
(src.file_id, src.value.generic_param_list())
|
||||
}
|
||||
GenericDefId::AdtId(AdtId::UnionId(it)) => {
|
||||
let src = it.lookup(db).source(db);
|
||||
(src.file_id, src.value.generic_param_list())
|
||||
}
|
||||
GenericDefId::AdtId(AdtId::EnumId(it)) => {
|
||||
let src = it.lookup(db).source(db);
|
||||
(src.file_id, src.value.generic_param_list())
|
||||
}
|
||||
GenericDefId::TraitId(it) => {
|
||||
let src = it.lookup(db).source(db);
|
||||
(src.file_id, src.value.generic_param_list())
|
||||
}
|
||||
GenericDefId::TraitAliasId(it) => {
|
||||
let src = it.lookup(db).source(db);
|
||||
(src.file_id, src.value.generic_param_list())
|
||||
}
|
||||
GenericDefId::TypeAliasId(it) => {
|
||||
let src = it.lookup(db).source(db);
|
||||
(src.file_id, src.value.generic_param_list())
|
||||
}
|
||||
GenericDefId::ImplId(it) => {
|
||||
let src = it.lookup(db).source(db);
|
||||
(src.file_id, src.value.generic_param_list())
|
||||
}
|
||||
GenericDefId::FunctionId(it) => file_id_and_params_of_item_loc(db, it),
|
||||
GenericDefId::TypeAliasId(it) => file_id_and_params_of_item_loc(db, it),
|
||||
GenericDefId::ConstId(_) => (FileId::BOGUS.into(), None),
|
||||
GenericDefId::AdtId(AdtId::StructId(it)) => file_id_and_params_of_item_loc(db, it),
|
||||
GenericDefId::AdtId(AdtId::UnionId(it)) => file_id_and_params_of_item_loc(db, it),
|
||||
GenericDefId::AdtId(AdtId::EnumId(it)) => file_id_and_params_of_item_loc(db, it),
|
||||
GenericDefId::TraitId(it) => file_id_and_params_of_item_loc(db, it),
|
||||
GenericDefId::TraitAliasId(it) => file_id_and_params_of_item_loc(db, it),
|
||||
GenericDefId::ImplId(it) => file_id_and_params_of_item_loc(db, it),
|
||||
// We won't be using this ID anyway
|
||||
GenericDefId::EnumVariantId(_) | GenericDefId::ConstId(_) => (FileId::BOGUS.into(), None),
|
||||
GenericDefId::EnumVariantId(_) => (FileId::BOGUS.into(), None),
|
||||
}
|
||||
}
|
||||
|
||||
fn file_id_and_params_of_item_loc<Loc>(
|
||||
db: &dyn DefDatabase,
|
||||
def: impl for<'db> Lookup<Database<'db> = dyn DefDatabase + 'db, Data = Loc>,
|
||||
) -> (HirFileId, Option<ast::GenericParamList>)
|
||||
where
|
||||
Loc: HasSource,
|
||||
Loc::Value: HasGenericParams,
|
||||
{
|
||||
let src = def.lookup(db).source(db);
|
||||
(src.file_id, src.value.generic_param_list())
|
||||
}
|
||||
|
||||
impl HasChildSource<LocalTypeOrConstParamId> for GenericDefId {
|
||||
type Value = Either<ast::TypeOrConstParam, ast::TraitOrAlias>;
|
||||
fn child_source(
|
||||
|
@ -559,7 +548,7 @@ impl HasChildSource<LocalTypeOrConstParamId> for GenericDefId {
|
|||
let generic_params = db.generic_params(*self);
|
||||
let mut idx_iter = generic_params.type_or_consts.iter().map(|(idx, _)| idx);
|
||||
|
||||
let (file_id, generic_params_list) = file_id_and_params_of(*self, db);
|
||||
let (file_id, generic_params_list) = file_id_and_params_of(db, *self);
|
||||
|
||||
let mut params = ArenaMap::default();
|
||||
|
||||
|
@ -598,7 +587,7 @@ impl HasChildSource<LocalLifetimeParamId> for GenericDefId {
|
|||
let generic_params = db.generic_params(*self);
|
||||
let idx_iter = generic_params.lifetimes.iter().map(|(idx, _)| idx);
|
||||
|
||||
let (file_id, generic_params_list) = file_id_and_params_of(*self, db);
|
||||
let (file_id, generic_params_list) = file_id_and_params_of(db, *self);
|
||||
|
||||
let mut params = ArenaMap::default();
|
||||
|
||||
|
@ -614,7 +603,7 @@ impl HasChildSource<LocalLifetimeParamId> for GenericDefId {
|
|||
|
||||
impl ChildBySource for GenericDefId {
|
||||
fn child_by_source_to(&self, db: &dyn DefDatabase, res: &mut DynMap, file_id: HirFileId) {
|
||||
let (gfile_id, generic_params_list) = file_id_and_params_of(*self, db);
|
||||
let (gfile_id, generic_params_list) = file_id_and_params_of(db, *self);
|
||||
if gfile_id != file_id {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -986,17 +986,13 @@ impl VariantId {
|
|||
}
|
||||
|
||||
pub trait HasModule {
|
||||
/// Returns the enclosing module this thing is defined within.
|
||||
fn module(&self, db: &dyn DefDatabase) -> ModuleId;
|
||||
}
|
||||
|
||||
impl HasModule for ItemContainerId {
|
||||
fn module(&self, db: &dyn DefDatabase) -> ModuleId {
|
||||
match *self {
|
||||
ItemContainerId::ModuleId(it) => it,
|
||||
ItemContainerId::ImplId(it) => it.lookup(db).container,
|
||||
ItemContainerId::TraitId(it) => it.lookup(db).container,
|
||||
ItemContainerId::ExternBlockId(it) => it.lookup(db).container,
|
||||
}
|
||||
/// Returns the crate this thing is defined within.
|
||||
#[inline]
|
||||
#[doc(alias = "crate")]
|
||||
fn krate(&self, db: &dyn DefDatabase) -> CrateId {
|
||||
self.module(db).krate
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1007,23 +1003,71 @@ impl<N: ItemTreeModItemNode> HasModule for AssocItemLoc<N> {
|
|||
}
|
||||
}
|
||||
|
||||
impl HasModule for AdtId {
|
||||
fn module(&self, db: &dyn DefDatabase) -> ModuleId {
|
||||
match self {
|
||||
AdtId::StructId(it) => it.lookup(db).container,
|
||||
AdtId::UnionId(it) => it.lookup(db).container,
|
||||
AdtId::EnumId(it) => it.lookup(db).container,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl HasModule for EnumId {
|
||||
impl<N, ItemId> HasModule for ItemId
|
||||
where
|
||||
N: ItemTreeModItemNode,
|
||||
ItemId: for<'db> Lookup<Database<'db> = dyn DefDatabase + 'db, Data = ItemLoc<N>> + Copy,
|
||||
{
|
||||
#[inline]
|
||||
fn module(&self, db: &dyn DefDatabase) -> ModuleId {
|
||||
self.lookup(db).container
|
||||
}
|
||||
}
|
||||
|
||||
// Technically this does not overlap with the above, but rustc currently forbids this, hence why we
|
||||
// need to write the 3 impls manually instead
|
||||
// impl<N, ItemId> HasModule for ItemId
|
||||
// where
|
||||
// N: ItemTreeModItemNode,
|
||||
// ItemId: for<'db> Lookup<Database<'db> = dyn DefDatabase + 'db, Data = AssocItemLoc<N>> + Copy,
|
||||
// {
|
||||
// #[inline]
|
||||
// fn module(&self, db: &dyn DefDatabase) -> ModuleId {
|
||||
// self.lookup(db).container.module(db)
|
||||
// }
|
||||
// }
|
||||
|
||||
// region: manual-assoc-has-module-impls
|
||||
#[inline]
|
||||
fn module_for_assoc_item_loc<'db>(
|
||||
db: &(dyn 'db + DefDatabase),
|
||||
id: impl Lookup<
|
||||
Database<'db> = dyn DefDatabase + 'db,
|
||||
Data = AssocItemLoc<impl ItemTreeModItemNode>,
|
||||
>,
|
||||
) -> ModuleId {
|
||||
id.lookup(db).container.module(db)
|
||||
}
|
||||
|
||||
impl HasModule for FunctionId {
|
||||
#[inline]
|
||||
fn module(&self, db: &dyn DefDatabase) -> ModuleId {
|
||||
module_for_assoc_item_loc(db, *self)
|
||||
}
|
||||
}
|
||||
|
||||
impl HasModule for ConstId {
|
||||
#[inline]
|
||||
fn module(&self, db: &dyn DefDatabase) -> ModuleId {
|
||||
module_for_assoc_item_loc(db, *self)
|
||||
}
|
||||
}
|
||||
|
||||
impl HasModule for StaticId {
|
||||
#[inline]
|
||||
fn module(&self, db: &dyn DefDatabase) -> ModuleId {
|
||||
module_for_assoc_item_loc(db, *self)
|
||||
}
|
||||
}
|
||||
|
||||
impl HasModule for TypeAliasId {
|
||||
#[inline]
|
||||
fn module(&self, db: &dyn DefDatabase) -> ModuleId {
|
||||
module_for_assoc_item_loc(db, *self)
|
||||
}
|
||||
}
|
||||
// endregion: manual-assoc-has-module-impls
|
||||
|
||||
impl HasModule for EnumVariantId {
|
||||
#[inline]
|
||||
fn module(&self, db: &dyn DefDatabase) -> ModuleId {
|
||||
|
@ -1031,46 +1075,81 @@ impl HasModule for EnumVariantId {
|
|||
}
|
||||
}
|
||||
|
||||
impl HasModule for ExternCrateId {
|
||||
impl HasModule for MacroRulesId {
|
||||
#[inline]
|
||||
fn module(&self, db: &dyn DefDatabase) -> ModuleId {
|
||||
self.lookup(db).container
|
||||
}
|
||||
}
|
||||
|
||||
impl HasModule for Macro2Id {
|
||||
#[inline]
|
||||
fn module(&self, db: &dyn DefDatabase) -> ModuleId {
|
||||
self.lookup(db).container
|
||||
}
|
||||
}
|
||||
|
||||
impl HasModule for ProcMacroId {
|
||||
#[inline]
|
||||
fn module(&self, db: &dyn DefDatabase) -> ModuleId {
|
||||
self.lookup(db).container.into()
|
||||
}
|
||||
}
|
||||
|
||||
impl HasModule for ItemContainerId {
|
||||
fn module(&self, db: &dyn DefDatabase) -> ModuleId {
|
||||
match *self {
|
||||
ItemContainerId::ModuleId(it) => it,
|
||||
ItemContainerId::ImplId(it) => it.module(db),
|
||||
ItemContainerId::TraitId(it) => it.module(db),
|
||||
ItemContainerId::ExternBlockId(it) => it.module(db),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl HasModule for AdtId {
|
||||
fn module(&self, db: &dyn DefDatabase) -> ModuleId {
|
||||
match *self {
|
||||
AdtId::StructId(it) => it.module(db),
|
||||
AdtId::UnionId(it) => it.module(db),
|
||||
AdtId::EnumId(it) => it.module(db),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl HasModule for VariantId {
|
||||
fn module(&self, db: &dyn DefDatabase) -> ModuleId {
|
||||
match self {
|
||||
VariantId::EnumVariantId(it) => it.lookup(db).parent.module(db),
|
||||
VariantId::StructId(it) => it.lookup(db).container,
|
||||
VariantId::UnionId(it) => it.lookup(db).container,
|
||||
match *self {
|
||||
VariantId::EnumVariantId(it) => it.module(db),
|
||||
VariantId::StructId(it) => it.module(db),
|
||||
VariantId::UnionId(it) => it.module(db),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl HasModule for MacroId {
|
||||
fn module(&self, db: &dyn DefDatabase) -> ModuleId {
|
||||
match self {
|
||||
MacroId::MacroRulesId(it) => it.lookup(db).container,
|
||||
MacroId::Macro2Id(it) => it.lookup(db).container,
|
||||
MacroId::ProcMacroId(it) => it.lookup(db).container.into(),
|
||||
match *self {
|
||||
MacroId::MacroRulesId(it) => it.module(db),
|
||||
MacroId::Macro2Id(it) => it.module(db),
|
||||
MacroId::ProcMacroId(it) => it.module(db),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl HasModule for TypeOwnerId {
|
||||
fn module(&self, db: &dyn DefDatabase) -> ModuleId {
|
||||
match self {
|
||||
TypeOwnerId::FunctionId(it) => it.lookup(db).module(db),
|
||||
TypeOwnerId::StaticId(it) => it.lookup(db).module(db),
|
||||
TypeOwnerId::ConstId(it) => it.lookup(db).module(db),
|
||||
TypeOwnerId::InTypeConstId(it) => it.lookup(db).owner.module(db),
|
||||
match *self {
|
||||
TypeOwnerId::FunctionId(it) => it.module(db),
|
||||
TypeOwnerId::StaticId(it) => it.module(db),
|
||||
TypeOwnerId::ConstId(it) => it.module(db),
|
||||
TypeOwnerId::AdtId(it) => it.module(db),
|
||||
TypeOwnerId::TraitId(it) => it.lookup(db).container,
|
||||
TypeOwnerId::TraitAliasId(it) => it.lookup(db).container,
|
||||
TypeOwnerId::TypeAliasId(it) => it.lookup(db).module(db),
|
||||
TypeOwnerId::ImplId(it) => it.lookup(db).container,
|
||||
TypeOwnerId::EnumVariantId(it) => it.lookup(db).parent.module(db),
|
||||
TypeOwnerId::TraitId(it) => it.module(db),
|
||||
TypeOwnerId::TraitAliasId(it) => it.module(db),
|
||||
TypeOwnerId::TypeAliasId(it) => it.module(db),
|
||||
TypeOwnerId::ImplId(it) => it.module(db),
|
||||
TypeOwnerId::EnumVariantId(it) => it.module(db),
|
||||
TypeOwnerId::InTypeConstId(it) => it.lookup(db).owner.module(db),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1078,10 +1157,10 @@ impl HasModule for TypeOwnerId {
|
|||
impl HasModule for DefWithBodyId {
|
||||
fn module(&self, db: &dyn DefDatabase) -> ModuleId {
|
||||
match self {
|
||||
DefWithBodyId::FunctionId(it) => it.lookup(db).module(db),
|
||||
DefWithBodyId::StaticId(it) => it.lookup(db).module(db),
|
||||
DefWithBodyId::ConstId(it) => it.lookup(db).module(db),
|
||||
DefWithBodyId::VariantId(it) => it.lookup(db).parent.module(db),
|
||||
DefWithBodyId::FunctionId(it) => it.module(db),
|
||||
DefWithBodyId::StaticId(it) => it.module(db),
|
||||
DefWithBodyId::ConstId(it) => it.module(db),
|
||||
DefWithBodyId::VariantId(it) => it.module(db),
|
||||
DefWithBodyId::InTypeConstId(it) => it.lookup(db).owner.module(db),
|
||||
}
|
||||
}
|
||||
|
@ -1090,32 +1169,18 @@ impl HasModule for DefWithBodyId {
|
|||
impl HasModule for GenericDefId {
|
||||
fn module(&self, db: &dyn DefDatabase) -> ModuleId {
|
||||
match self {
|
||||
GenericDefId::FunctionId(it) => it.lookup(db).module(db),
|
||||
GenericDefId::FunctionId(it) => it.module(db),
|
||||
GenericDefId::AdtId(it) => it.module(db),
|
||||
GenericDefId::TraitId(it) => it.lookup(db).container,
|
||||
GenericDefId::TraitAliasId(it) => it.lookup(db).container,
|
||||
GenericDefId::TypeAliasId(it) => it.lookup(db).module(db),
|
||||
GenericDefId::ImplId(it) => it.lookup(db).container,
|
||||
GenericDefId::EnumVariantId(it) => it.lookup(db).parent.lookup(db).container,
|
||||
GenericDefId::ConstId(it) => it.lookup(db).module(db),
|
||||
GenericDefId::TraitId(it) => it.module(db),
|
||||
GenericDefId::TraitAliasId(it) => it.module(db),
|
||||
GenericDefId::TypeAliasId(it) => it.module(db),
|
||||
GenericDefId::ImplId(it) => it.module(db),
|
||||
GenericDefId::EnumVariantId(it) => it.module(db),
|
||||
GenericDefId::ConstId(it) => it.module(db),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl HasModule for TypeAliasId {
|
||||
#[inline]
|
||||
fn module(&self, db: &dyn DefDatabase) -> ModuleId {
|
||||
self.lookup(db).module(db)
|
||||
}
|
||||
}
|
||||
|
||||
impl HasModule for TraitId {
|
||||
#[inline]
|
||||
fn module(&self, db: &dyn DefDatabase) -> ModuleId {
|
||||
self.lookup(db).container
|
||||
}
|
||||
}
|
||||
|
||||
impl ModuleDefId {
|
||||
/// Returns the module containing `self` (or `self`, if `self` is itself a module).
|
||||
///
|
||||
|
@ -1123,14 +1188,14 @@ impl ModuleDefId {
|
|||
pub fn module(&self, db: &dyn DefDatabase) -> Option<ModuleId> {
|
||||
Some(match self {
|
||||
ModuleDefId::ModuleId(id) => *id,
|
||||
ModuleDefId::FunctionId(id) => id.lookup(db).module(db),
|
||||
ModuleDefId::FunctionId(id) => id.module(db),
|
||||
ModuleDefId::AdtId(id) => id.module(db),
|
||||
ModuleDefId::EnumVariantId(id) => id.lookup(db).parent.module(db),
|
||||
ModuleDefId::ConstId(id) => id.lookup(db).container.module(db),
|
||||
ModuleDefId::StaticId(id) => id.lookup(db).module(db),
|
||||
ModuleDefId::TraitId(id) => id.lookup(db).container,
|
||||
ModuleDefId::TraitAliasId(id) => id.lookup(db).container,
|
||||
ModuleDefId::TypeAliasId(id) => id.lookup(db).module(db),
|
||||
ModuleDefId::EnumVariantId(id) => id.module(db),
|
||||
ModuleDefId::ConstId(id) => id.module(db),
|
||||
ModuleDefId::StaticId(id) => id.module(db),
|
||||
ModuleDefId::TraitId(id) => id.module(db),
|
||||
ModuleDefId::TraitAliasId(id) => id.module(db),
|
||||
ModuleDefId::TypeAliasId(id) => id.module(db),
|
||||
ModuleDefId::MacroId(id) => id.module(db),
|
||||
ModuleDefId::BuiltinType(_) => return None,
|
||||
})
|
||||
|
@ -1139,31 +1204,28 @@ impl ModuleDefId {
|
|||
|
||||
impl AttrDefId {
|
||||
pub fn krate(&self, db: &dyn DefDatabase) -> CrateId {
|
||||
match self {
|
||||
match *self {
|
||||
AttrDefId::ModuleId(it) => it.krate,
|
||||
AttrDefId::FieldId(it) => it.parent.module(db).krate,
|
||||
AttrDefId::AdtId(it) => it.module(db).krate,
|
||||
AttrDefId::FunctionId(it) => it.lookup(db).module(db).krate,
|
||||
AttrDefId::EnumVariantId(it) => it.lookup(db).parent.module(db).krate,
|
||||
AttrDefId::StaticId(it) => it.lookup(db).module(db).krate,
|
||||
AttrDefId::ConstId(it) => it.lookup(db).module(db).krate,
|
||||
AttrDefId::TraitId(it) => it.lookup(db).container.krate,
|
||||
AttrDefId::TraitAliasId(it) => it.lookup(db).container.krate,
|
||||
AttrDefId::TypeAliasId(it) => it.lookup(db).module(db).krate,
|
||||
AttrDefId::ImplId(it) => it.lookup(db).container.krate,
|
||||
AttrDefId::ExternBlockId(it) => it.lookup(db).container.krate,
|
||||
AttrDefId::GenericParamId(it) => {
|
||||
match it {
|
||||
GenericParamId::TypeParamId(it) => it.parent(),
|
||||
GenericParamId::ConstParamId(it) => it.parent(),
|
||||
GenericParamId::LifetimeParamId(it) => it.parent,
|
||||
}
|
||||
.module(db)
|
||||
.krate
|
||||
AttrDefId::FieldId(it) => it.parent.krate(db),
|
||||
AttrDefId::AdtId(it) => it.krate(db),
|
||||
AttrDefId::FunctionId(it) => it.krate(db),
|
||||
AttrDefId::EnumVariantId(it) => it.krate(db),
|
||||
AttrDefId::StaticId(it) => it.krate(db),
|
||||
AttrDefId::ConstId(it) => it.krate(db),
|
||||
AttrDefId::TraitId(it) => it.krate(db),
|
||||
AttrDefId::TraitAliasId(it) => it.krate(db),
|
||||
AttrDefId::TypeAliasId(it) => it.krate(db),
|
||||
AttrDefId::ImplId(it) => it.krate(db),
|
||||
AttrDefId::ExternBlockId(it) => it.krate(db),
|
||||
AttrDefId::GenericParamId(it) => match it {
|
||||
GenericParamId::TypeParamId(it) => it.parent(),
|
||||
GenericParamId::ConstParamId(it) => it.parent(),
|
||||
GenericParamId::LifetimeParamId(it) => it.parent,
|
||||
}
|
||||
AttrDefId::MacroId(it) => it.module(db).krate,
|
||||
AttrDefId::ExternCrateId(it) => it.lookup(db).container.krate,
|
||||
AttrDefId::UseId(it) => it.lookup(db).container.krate,
|
||||
.krate(db),
|
||||
AttrDefId::MacroId(it) => it.krate(db),
|
||||
AttrDefId::ExternCrateId(it) => it.krate(db),
|
||||
AttrDefId::UseId(it) => it.krate(db),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1910,7 +1910,7 @@ impl Function {
|
|||
return None;
|
||||
}
|
||||
let loc = self.id.lookup(db.upcast());
|
||||
let def_map = db.crate_def_map(loc.krate(db).into());
|
||||
let def_map = db.crate_def_map(HasModule::krate(&loc, db.upcast()));
|
||||
def_map.fn_as_proc_macro(self.id).map(|id| Macro { id: id.into() })
|
||||
}
|
||||
|
||||
|
@ -2516,11 +2516,13 @@ pub enum AssocItem {
|
|||
Const(Const),
|
||||
TypeAlias(TypeAlias),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum AssocItemContainer {
|
||||
Trait(Trait),
|
||||
Impl(Impl),
|
||||
}
|
||||
|
||||
pub trait AsAssocItem {
|
||||
fn as_assoc_item(self, db: &dyn HirDatabase) -> Option<AssocItem>;
|
||||
}
|
||||
|
@ -2530,16 +2532,19 @@ impl AsAssocItem for Function {
|
|||
as_assoc_item(db, AssocItem::Function, self.id)
|
||||
}
|
||||
}
|
||||
|
||||
impl AsAssocItem for Const {
|
||||
fn as_assoc_item(self, db: &dyn HirDatabase) -> Option<AssocItem> {
|
||||
as_assoc_item(db, AssocItem::Const, self.id)
|
||||
}
|
||||
}
|
||||
|
||||
impl AsAssocItem for TypeAlias {
|
||||
fn as_assoc_item(self, db: &dyn HirDatabase) -> Option<AssocItem> {
|
||||
as_assoc_item(db, AssocItem::TypeAlias, self.id)
|
||||
}
|
||||
}
|
||||
|
||||
impl AsAssocItem for ModuleDef {
|
||||
fn as_assoc_item(self, db: &dyn HirDatabase) -> Option<AssocItem> {
|
||||
match self {
|
||||
|
@ -2550,6 +2555,7 @@ impl AsAssocItem for ModuleDef {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AsAssocItem for DefWithBody {
|
||||
fn as_assoc_item(self, db: &dyn HirDatabase) -> Option<AssocItem> {
|
||||
match self {
|
||||
|
@ -2560,15 +2566,14 @@ impl AsAssocItem for DefWithBody {
|
|||
}
|
||||
}
|
||||
|
||||
fn as_assoc_item<'db, ID, DEF, CTOR, AST>(
|
||||
fn as_assoc_item<'db, ID, DEF, AST>(
|
||||
db: &(dyn HirDatabase + 'db),
|
||||
ctor: CTOR,
|
||||
ctor: impl FnOnce(DEF) -> AssocItem,
|
||||
id: ID,
|
||||
) -> Option<AssocItem>
|
||||
where
|
||||
ID: Lookup<Database<'db> = dyn DefDatabase + 'db, Data = AssocItemLoc<AST>>,
|
||||
DEF: From<ID>,
|
||||
CTOR: FnOnce(DEF) -> AssocItem,
|
||||
AST: ItemTreeModItemNode,
|
||||
{
|
||||
match id.lookup(db.upcast()).container {
|
||||
|
@ -2609,27 +2614,34 @@ impl AssocItem {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn containing_trait(self, db: &dyn HirDatabase) -> Option<Trait> {
|
||||
pub fn container_trait(self, db: &dyn HirDatabase) -> Option<Trait> {
|
||||
match self.container(db) {
|
||||
AssocItemContainer::Trait(t) => Some(t),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn containing_trait_impl(self, db: &dyn HirDatabase) -> Option<Trait> {
|
||||
pub fn implemented_trait(self, db: &dyn HirDatabase) -> Option<Trait> {
|
||||
match self.container(db) {
|
||||
AssocItemContainer::Impl(i) => i.trait_(db),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn containing_trait_or_trait_impl(self, db: &dyn HirDatabase) -> Option<Trait> {
|
||||
pub fn container_or_implemented_trait(self, db: &dyn HirDatabase) -> Option<Trait> {
|
||||
match self.container(db) {
|
||||
AssocItemContainer::Trait(t) => Some(t),
|
||||
AssocItemContainer::Impl(i) => i.trait_(db),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn implementing_ty(self, db: &dyn HirDatabase) -> Option<Type> {
|
||||
match self.container(db) {
|
||||
AssocItemContainer::Impl(i) => Some(i.self_ty(db)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_function(self) -> Option<Function> {
|
||||
match self {
|
||||
Self::Function(v) => Some(v),
|
||||
|
@ -3321,7 +3333,7 @@ impl Impl {
|
|||
}
|
||||
|
||||
pub fn items(self, db: &dyn HirDatabase) -> Vec<AssocItem> {
|
||||
db.impl_data(self.id).items.iter().map(|it| (*it).into()).collect()
|
||||
db.impl_data(self.id).items.iter().map(|&it| it.into()).collect()
|
||||
}
|
||||
|
||||
pub fn is_negative(self, db: &dyn HirDatabase) -> bool {
|
||||
|
@ -3677,7 +3689,7 @@ impl Type {
|
|||
.and_then(|it| {
|
||||
let into_future_fn = it.as_function()?;
|
||||
let assoc_item = as_assoc_item(db, AssocItem::Function, into_future_fn)?;
|
||||
let into_future_trait = assoc_item.containing_trait_or_trait_impl(db)?;
|
||||
let into_future_trait = assoc_item.container_or_implemented_trait(db)?;
|
||||
Some(into_future_trait.id)
|
||||
})
|
||||
.or_else(|| {
|
||||
|
|
|
@ -163,9 +163,8 @@ pub(crate) fn convert_bool_then_to_if(acc: &mut Assists, ctx: &AssistContext<'_>
|
|||
return None;
|
||||
}
|
||||
let assoc = func.as_assoc_item(ctx.sema.db)?;
|
||||
match assoc.container(ctx.sema.db) {
|
||||
hir::AssocItemContainer::Impl(impl_) if impl_.self_ty(ctx.sema.db).is_bool() => {}
|
||||
_ => return None,
|
||||
if !assoc.implementing_ty(ctx.sema.db)?.is_bool() {
|
||||
return None;
|
||||
}
|
||||
|
||||
let target = mcall.syntax().text_range();
|
||||
|
|
|
@ -364,7 +364,7 @@ fn is_in_trait_impl(ast_func: &ast::Fn, ctx: &AssistContext<'_>) -> bool {
|
|||
ctx.sema
|
||||
.to_def(ast_func)
|
||||
.and_then(|hir_func| hir_func.as_assoc_item(ctx.db()))
|
||||
.and_then(|assoc_item| assoc_item.containing_trait_impl(ctx.db()))
|
||||
.and_then(|assoc_item| assoc_item.implemented_trait(ctx.db()))
|
||||
.is_some()
|
||||
}
|
||||
|
||||
|
@ -373,7 +373,7 @@ fn is_in_trait_def(ast_func: &ast::Fn, ctx: &AssistContext<'_>) -> bool {
|
|||
ctx.sema
|
||||
.to_def(ast_func)
|
||||
.and_then(|hir_func| hir_func.as_assoc_item(ctx.db()))
|
||||
.and_then(|assoc_item| assoc_item.containing_trait(ctx.db()))
|
||||
.and_then(|assoc_item| assoc_item.container_trait(ctx.db()))
|
||||
.is_some()
|
||||
}
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ pub(crate) fn into_to_qualified_from(acc: &mut Assists, ctx: &AssistContext<'_>)
|
|||
let fnc = sema.resolve_method_call(&method_call)?;
|
||||
let scope = sema.scope(method_call.syntax())?;
|
||||
// Check if the method call refers to Into trait.
|
||||
if fnc.as_assoc_item(db)?.containing_trait_impl(db)?
|
||||
if fnc.as_assoc_item(db)?.implemented_trait(db)?
|
||||
== FamousDefs(sema, scope.krate()).core_convert_Into()?
|
||||
{
|
||||
let type_call = sema.type_of_expr(&method_call.clone().into())?;
|
||||
|
|
|
@ -203,7 +203,7 @@ fn item_as_trait(db: &RootDatabase, item: hir::ItemInNs) -> Option<hir::Trait> {
|
|||
|
||||
match item_module_def {
|
||||
hir::ModuleDef::Trait(trait_) => Some(trait_),
|
||||
_ => item_module_def.as_assoc_item(db)?.containing_trait(db),
|
||||
_ => item_module_def.as_assoc_item(db)?.container_trait(db),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -112,7 +112,7 @@ impl<'a> RenderContext<'a> {
|
|||
};
|
||||
is_assoc_deprecated
|
||||
|| assoc
|
||||
.containing_trait_or_trait_impl(db)
|
||||
.container_or_implemented_trait(db)
|
||||
.map(|trait_| self.is_deprecated(trait_))
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ fn render(ctx: RenderContext<'_>, const_: hir::Const) -> Option<CompletionItem>
|
|||
.set_relevance(ctx.completion_relevance());
|
||||
|
||||
if let Some(actm) = const_.as_assoc_item(db) {
|
||||
if let Some(trt) = actm.containing_trait_or_trait_impl(db) {
|
||||
if let Some(trt) = actm.container_or_implemented_trait(db) {
|
||||
item.trait_name(trt.name(db).to_smol_str());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ fn render(
|
|||
let ret_type = func.ret_type(db);
|
||||
let assoc_item = func.as_assoc_item(db);
|
||||
|
||||
let trait_ = assoc_item.and_then(|trait_| trait_.containing_trait_or_trait_impl(db));
|
||||
let trait_ = assoc_item.and_then(|trait_| trait_.container_or_implemented_trait(db));
|
||||
let is_op_method = trait_.map_or(false, |trait_| completion.is_ops_trait(trait_));
|
||||
|
||||
let is_item_from_notable_trait =
|
||||
|
@ -145,7 +145,7 @@ fn render(
|
|||
}
|
||||
None => {
|
||||
if let Some(actm) = assoc_item {
|
||||
if let Some(trt) = actm.containing_trait_or_trait_impl(db) {
|
||||
if let Some(trt) = actm.container_or_implemented_trait(db) {
|
||||
item.trait_name(trt.name(db).to_smol_str());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ fn render(
|
|||
.set_relevance(ctx.completion_relevance());
|
||||
|
||||
if let Some(actm) = type_alias.as_assoc_item(db) {
|
||||
if let Some(trt) = actm.containing_trait_or_trait_impl(db) {
|
||||
if let Some(trt) = actm.container_or_implemented_trait(db) {
|
||||
item.trait_name(trt.name(db).to_smol_str());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -206,7 +206,7 @@ impl Definition {
|
|||
// docs are missing, for assoc items of trait impls try to fall back to the docs of the
|
||||
// original item of the trait
|
||||
let assoc = self.as_assoc_item(db)?;
|
||||
let trait_ = assoc.containing_trait_impl(db)?;
|
||||
let trait_ = assoc.implemented_trait(db)?;
|
||||
let name = Some(assoc.name(db)?);
|
||||
let item = trait_.items(db).into_iter().find(|it| it.name(db) == name)?;
|
||||
item.docs(db)
|
||||
|
|
|
@ -529,7 +529,7 @@ fn trait_applicable_items(
|
|||
return None;
|
||||
}
|
||||
|
||||
let assoc_item_trait = assoc.containing_trait(db)?;
|
||||
let assoc_item_trait = assoc.container_trait(db)?;
|
||||
if related_traits.contains(&assoc_item_trait) {
|
||||
return None;
|
||||
}
|
||||
|
@ -550,8 +550,7 @@ fn trait_applicable_items(
|
|||
None,
|
||||
|assoc| {
|
||||
if required_assoc_items.contains(&assoc) {
|
||||
let located_trait =
|
||||
assoc.containing_trait(db).filter(|&it| scope_filter(it))?;
|
||||
let located_trait = assoc.container_trait(db).filter(|&it| scope_filter(it))?;
|
||||
let trait_item = ItemInNs::from(ModuleDef::from(located_trait));
|
||||
let import_path = trait_import_paths
|
||||
.entry(trait_item)
|
||||
|
@ -576,8 +575,7 @@ fn trait_applicable_items(
|
|||
|function| {
|
||||
let assoc = function.as_assoc_item(db)?;
|
||||
if required_assoc_items.contains(&assoc) {
|
||||
let located_trait =
|
||||
assoc.containing_trait(db).filter(|&it| scope_filter(it))?;
|
||||
let located_trait = assoc.container_trait(db).filter(|&it| scope_filter(it))?;
|
||||
let trait_item = ItemInNs::from(ModuleDef::from(located_trait));
|
||||
let import_path = trait_import_paths
|
||||
.entry(trait_item)
|
||||
|
|
|
@ -75,7 +75,7 @@ pub fn get_missing_assoc_items(
|
|||
pub(crate) fn convert_to_def_in_trait(db: &dyn HirDatabase, def: Definition) -> Definition {
|
||||
(|| {
|
||||
let assoc = def.as_assoc_item(db)?;
|
||||
let trait_ = assoc.containing_trait_impl(db)?;
|
||||
let trait_ = assoc.implemented_trait(db)?;
|
||||
assoc_item_of_trait(db, assoc, trait_)
|
||||
})()
|
||||
.unwrap_or(def)
|
||||
|
|
|
@ -668,7 +668,7 @@ fn get_assoc_item_fragment(db: &dyn HirDatabase, assoc_item: hir::AssocItem) ->
|
|||
Some(match assoc_item {
|
||||
AssocItem::Function(function) => {
|
||||
let is_trait_method =
|
||||
function.as_assoc_item(db).and_then(|assoc| assoc.containing_trait(db)).is_some();
|
||||
function.as_assoc_item(db).and_then(|assoc| assoc.container_trait(db)).is_some();
|
||||
// This distinction may get more complicated when specialization is available.
|
||||
// Rustdoc makes this decision based on whether a method 'has defaultness'.
|
||||
// Currently this is only the case for provided trait methods.
|
||||
|
|
|
@ -61,7 +61,7 @@ pub(crate) fn goto_declaration(
|
|||
_ => None,
|
||||
}?;
|
||||
|
||||
let trait_ = assoc.containing_trait_impl(db)?;
|
||||
let trait_ = assoc.implemented_trait(db)?;
|
||||
let name = Some(assoc.name(db)?);
|
||||
let item = trait_.items(db).into_iter().find(|it| it.name(db) == name)?;
|
||||
item.try_to_nav(db)
|
||||
|
|
|
@ -182,11 +182,7 @@ fn try_filter_trait_item_definition(
|
|||
match assoc {
|
||||
AssocItem::Function(..) => None,
|
||||
AssocItem::Const(..) | AssocItem::TypeAlias(..) => {
|
||||
let imp = match assoc.container(db) {
|
||||
hir::AssocItemContainer::Impl(imp) => imp,
|
||||
_ => return None,
|
||||
};
|
||||
let trait_ = imp.trait_(db)?;
|
||||
let trait_ = assoc.implemented_trait(db)?;
|
||||
let name = def.name(db)?;
|
||||
let discri_value = discriminant(&assoc);
|
||||
trait_
|
||||
|
|
|
@ -60,13 +60,13 @@ pub(crate) fn goto_implementation(
|
|||
Definition::Function(f) => {
|
||||
let assoc = f.as_assoc_item(sema.db)?;
|
||||
let name = assoc.name(sema.db)?;
|
||||
let trait_ = assoc.containing_trait_or_trait_impl(sema.db)?;
|
||||
let trait_ = assoc.container_or_implemented_trait(sema.db)?;
|
||||
impls_for_trait_item(&sema, trait_, name)
|
||||
}
|
||||
Definition::Const(c) => {
|
||||
let assoc = c.as_assoc_item(sema.db)?;
|
||||
let name = assoc.name(sema.db)?;
|
||||
let trait_ = assoc.containing_trait_or_trait_impl(sema.db)?;
|
||||
let trait_ = assoc.container_or_implemented_trait(sema.db)?;
|
||||
impls_for_trait_item(&sema, trait_, name)
|
||||
}
|
||||
_ => return None,
|
||||
|
|
|
@ -442,8 +442,7 @@ fn module_def_doctest(db: &RootDatabase, def: Definition) -> Option<Runnable> {
|
|||
.for_each(|name| format_to!(path, "{}::", name.display(db)));
|
||||
// This probably belongs to canonical_path?
|
||||
if let Some(assoc_item) = def.as_assoc_item(db) {
|
||||
if let hir::AssocItemContainer::Impl(imp) = assoc_item.container(db) {
|
||||
let ty = imp.self_ty(db);
|
||||
if let Some(ty) = assoc_item.implementing_ty(db) {
|
||||
if let Some(adt) = ty.as_adt() {
|
||||
let name = adt.name(db);
|
||||
let mut ty_args = ty.generic_parameters(db).peekable();
|
||||
|
|
|
@ -559,7 +559,7 @@ fn highlight_method_call(
|
|||
}
|
||||
if func
|
||||
.as_assoc_item(sema.db)
|
||||
.and_then(|it| it.containing_trait_or_trait_impl(sema.db))
|
||||
.and_then(|it| it.container_or_implemented_trait(sema.db))
|
||||
.is_some()
|
||||
{
|
||||
h |= HlMod::Trait;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue