mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
Abstract over ItemTreeLoc
This commit is contained in:
parent
2ebf0c87c2
commit
00303c3b67
11 changed files with 160 additions and 229 deletions
|
@ -24,12 +24,11 @@ use triomphe::Arc;
|
|||
|
||||
use crate::{
|
||||
db::DefDatabase,
|
||||
item_tree::{AttrOwner, Fields, ItemTreeId, ItemTreeModItemNode},
|
||||
item_tree::{AttrOwner, Fields, ItemTreeNode},
|
||||
lang_item::LangItem,
|
||||
nameres::{ModuleOrigin, ModuleSource},
|
||||
src::{HasChildSource, HasSource},
|
||||
AdtId, AssocItemLoc, AttrDefId, GenericParamId, ItemLoc, LocalFieldId, Lookup, MacroId,
|
||||
VariantId,
|
||||
AdtId, AttrDefId, GenericParamId, ItemTreeLoc, LocalFieldId, Lookup, MacroId, VariantId,
|
||||
};
|
||||
|
||||
/// Desugared attributes of an item post `cfg_attr` expansion.
|
||||
|
@ -356,11 +355,7 @@ impl AttrsWithOwner {
|
|||
AttrDefId::FieldId(it) => {
|
||||
return db.fields_attrs(it.parent)[it.local_id].clone();
|
||||
}
|
||||
AttrDefId::EnumVariantId(it) => {
|
||||
let id = it.lookup(db).id;
|
||||
let tree = id.item_tree(db);
|
||||
tree.raw_attrs(id.value.into()).clone()
|
||||
}
|
||||
AttrDefId::EnumVariantId(it) => attrs_from_item_tree_loc(db, it),
|
||||
AttrDefId::AdtId(it) => match it {
|
||||
AdtId::StructId(it) => attrs_from_item_tree_loc(db, it),
|
||||
AdtId::EnumId(it) => attrs_from_item_tree_loc(db, it),
|
||||
|
@ -369,15 +364,15 @@ impl AttrsWithOwner {
|
|||
AttrDefId::TraitId(it) => attrs_from_item_tree_loc(db, it),
|
||||
AttrDefId::TraitAliasId(it) => attrs_from_item_tree_loc(db, it),
|
||||
AttrDefId::MacroId(it) => match it {
|
||||
MacroId::Macro2Id(it) => attrs_from_item_tree(db, it.lookup(db).id),
|
||||
MacroId::MacroRulesId(it) => attrs_from_item_tree(db, it.lookup(db).id),
|
||||
MacroId::ProcMacroId(it) => attrs_from_item_tree(db, it.lookup(db).id),
|
||||
MacroId::Macro2Id(it) => attrs_from_item_tree_loc(db, it),
|
||||
MacroId::MacroRulesId(it) => attrs_from_item_tree_loc(db, it),
|
||||
MacroId::ProcMacroId(it) => attrs_from_item_tree_loc(db, it),
|
||||
},
|
||||
AttrDefId::ImplId(it) => attrs_from_item_tree_loc(db, it),
|
||||
AttrDefId::ConstId(it) => attrs_from_item_tree_assoc(db, it),
|
||||
AttrDefId::StaticId(it) => attrs_from_item_tree_assoc(db, it),
|
||||
AttrDefId::FunctionId(it) => attrs_from_item_tree_assoc(db, it),
|
||||
AttrDefId::TypeAliasId(it) => attrs_from_item_tree_assoc(db, it),
|
||||
AttrDefId::ConstId(it) => attrs_from_item_tree_loc(db, it),
|
||||
AttrDefId::StaticId(it) => attrs_from_item_tree_loc(db, it),
|
||||
AttrDefId::FunctionId(it) => attrs_from_item_tree_loc(db, it),
|
||||
AttrDefId::TypeAliasId(it) => attrs_from_item_tree_loc(db, it),
|
||||
AttrDefId::GenericParamId(it) => match it {
|
||||
GenericParamId::ConstParamId(it) => {
|
||||
let src = it.parent().child_source(db);
|
||||
|
@ -602,29 +597,14 @@ fn any_has_attrs<'db>(
|
|||
id.lookup(db).source(db).map(ast::AnyHasAttrs::new)
|
||||
}
|
||||
|
||||
fn attrs_from_item_tree<N: ItemTreeModItemNode>(
|
||||
db: &dyn DefDatabase,
|
||||
id: ItemTreeId<N>,
|
||||
fn attrs_from_item_tree_loc<'db, N: ItemTreeNode>(
|
||||
db: &(dyn DefDatabase + 'db),
|
||||
lookup: impl Lookup<Database<'db> = dyn DefDatabase + 'db, Data = impl ItemTreeLoc<Id = N>>,
|
||||
) -> RawAttrs {
|
||||
let id = lookup.lookup(db).item_tree_id();
|
||||
let tree = id.item_tree(db);
|
||||
let mod_item = N::id_to_mod_item(id.value);
|
||||
tree.raw_attrs(mod_item.into()).clone()
|
||||
}
|
||||
|
||||
fn attrs_from_item_tree_loc<'db, N: ItemTreeModItemNode>(
|
||||
db: &(dyn DefDatabase + 'db),
|
||||
lookup: impl Lookup<Database<'db> = dyn DefDatabase + 'db, Data = ItemLoc<N>>,
|
||||
) -> RawAttrs {
|
||||
let id = lookup.lookup(db).id;
|
||||
attrs_from_item_tree(db, id)
|
||||
}
|
||||
|
||||
fn attrs_from_item_tree_assoc<'db, N: ItemTreeModItemNode>(
|
||||
db: &(dyn DefDatabase + 'db),
|
||||
lookup: impl Lookup<Database<'db> = dyn DefDatabase + 'db, Data = AssocItemLoc<N>>,
|
||||
) -> RawAttrs {
|
||||
let id = lookup.lookup(db).id;
|
||||
attrs_from_item_tree(db, id)
|
||||
let attr_owner = N::attr_owner(id.value);
|
||||
tree.raw_attrs(attr_owner).clone()
|
||||
}
|
||||
|
||||
pub(crate) fn fields_attrs_source_map(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue