mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 11:20:54 +00:00
Remove FileItemTreeId
This commit is contained in:
parent
e9f8ecab45
commit
f3434f537f
@ -523,15 +523,10 @@ impl AttrsWithOwner {
|
||||
let mod_data = &def_map[module.local_id];
|
||||
|
||||
let raw_attrs = match mod_data.origin {
|
||||
ModuleOrigin::File {
|
||||
definition,
|
||||
declaration_tree_id,
|
||||
file_item_tree_id,
|
||||
..
|
||||
} => {
|
||||
ModuleOrigin::File { definition, declaration_tree_id, declaration, .. } => {
|
||||
let decl_attrs = declaration_tree_id
|
||||
.item_tree(db)
|
||||
.raw_attrs(AttrOwner::ModItem(file_item_tree_id.into()))
|
||||
.raw_attrs(AttrOwner::ModItem(declaration.into()))
|
||||
.clone();
|
||||
let tree = db.file_item_tree(definition.into());
|
||||
let def_attrs = tree.raw_attrs(AttrOwner::TopLevel).clone();
|
||||
@ -541,12 +536,10 @@ impl AttrsWithOwner {
|
||||
let tree = db.file_item_tree(definition.into());
|
||||
tree.raw_attrs(AttrOwner::TopLevel).clone()
|
||||
}
|
||||
ModuleOrigin::Inline { definition_tree_id, file_item_tree_id, .. } => {
|
||||
definition_tree_id
|
||||
.item_tree(db)
|
||||
.raw_attrs(AttrOwner::ModItem(file_item_tree_id.into()))
|
||||
.clone()
|
||||
}
|
||||
ModuleOrigin::Inline { definition_tree_id, definition } => definition_tree_id
|
||||
.item_tree(db)
|
||||
.raw_attrs(AttrOwner::ModItem(definition.into()))
|
||||
.clone(),
|
||||
ModuleOrigin::BlockExpr { id, .. } => {
|
||||
let tree = db.block_item_tree(id);
|
||||
tree.raw_attrs(AttrOwner::TopLevel).clone()
|
||||
|
@ -37,8 +37,8 @@ mod tests;
|
||||
|
||||
use std::{
|
||||
fmt::{self, Debug},
|
||||
hash::{Hash, Hasher},
|
||||
ops::{Index, Range},
|
||||
hash::Hash,
|
||||
ops::Index,
|
||||
sync::OnceLock,
|
||||
};
|
||||
|
||||
@ -51,7 +51,7 @@ use hir_expand::{
|
||||
name::Name,
|
||||
};
|
||||
use intern::Interned;
|
||||
use la_arena::{Arena, Idx, RawIdx};
|
||||
use la_arena::{Arena, Idx};
|
||||
use rustc_hash::FxHashMap;
|
||||
use smallvec::SmallVec;
|
||||
use span::{AstIdNode, Edition, FileAstId, SyntaxContext};
|
||||
@ -277,23 +277,23 @@ struct ItemVisibilities {
|
||||
|
||||
#[derive(Default, Debug, Eq, PartialEq)]
|
||||
struct ItemTreeData {
|
||||
uses: Arena<Use>,
|
||||
extern_crates: Arena<ExternCrate>,
|
||||
extern_blocks: Arena<ExternBlock>,
|
||||
functions: Arena<Function>,
|
||||
structs: Arena<Struct>,
|
||||
unions: Arena<Union>,
|
||||
enums: Arena<Enum>,
|
||||
consts: Arena<Const>,
|
||||
statics: Arena<Static>,
|
||||
traits: Arena<Trait>,
|
||||
trait_aliases: Arena<TraitAlias>,
|
||||
impls: Arena<Impl>,
|
||||
type_aliases: Arena<TypeAlias>,
|
||||
mods: Arena<Mod>,
|
||||
macro_calls: Arena<MacroCall>,
|
||||
macro_rules: Arena<MacroRules>,
|
||||
macro_defs: Arena<Macro2>,
|
||||
uses: FxHashMap<ItemTreeAstId<Use>, Use>,
|
||||
extern_crates: FxHashMap<ItemTreeAstId<ExternCrate>, ExternCrate>,
|
||||
extern_blocks: FxHashMap<ItemTreeAstId<ExternBlock>, ExternBlock>,
|
||||
functions: FxHashMap<ItemTreeAstId<Function>, Function>,
|
||||
structs: FxHashMap<ItemTreeAstId<Struct>, Struct>,
|
||||
unions: FxHashMap<ItemTreeAstId<Union>, Union>,
|
||||
enums: FxHashMap<ItemTreeAstId<Enum>, Enum>,
|
||||
consts: FxHashMap<ItemTreeAstId<Const>, Const>,
|
||||
statics: FxHashMap<ItemTreeAstId<Static>, Static>,
|
||||
traits: FxHashMap<ItemTreeAstId<Trait>, Trait>,
|
||||
trait_aliases: FxHashMap<ItemTreeAstId<TraitAlias>, TraitAlias>,
|
||||
impls: FxHashMap<ItemTreeAstId<Impl>, Impl>,
|
||||
type_aliases: FxHashMap<ItemTreeAstId<TypeAlias>, TypeAlias>,
|
||||
mods: FxHashMap<ItemTreeAstId<Mod>, Mod>,
|
||||
macro_calls: FxHashMap<ItemTreeAstId<MacroCall>, MacroCall>,
|
||||
macro_rules: FxHashMap<ItemTreeAstId<MacroRules>, MacroRules>,
|
||||
macro_defs: FxHashMap<ItemTreeAstId<Macro2>, Macro2>,
|
||||
|
||||
vis: ItemVisibilities,
|
||||
}
|
||||
@ -329,51 +329,11 @@ pub trait ItemTreeNode: Clone {
|
||||
fn ast_id(&self) -> FileAstId<Self::Source>;
|
||||
|
||||
/// Looks up an instance of `Self` in an item tree.
|
||||
fn lookup(tree: &ItemTree, index: Idx<Self>) -> &Self;
|
||||
fn lookup(tree: &ItemTree, index: FileAstId<Self::Source>) -> &Self;
|
||||
}
|
||||
|
||||
pub struct FileItemTreeId<N>(Idx<N>);
|
||||
|
||||
impl<N> FileItemTreeId<N> {
|
||||
pub fn range_iter(range: Range<Self>) -> impl Iterator<Item = Self> + Clone {
|
||||
(range.start.index().into_raw().into_u32()..range.end.index().into_raw().into_u32())
|
||||
.map(RawIdx::from_u32)
|
||||
.map(Idx::from_raw)
|
||||
.map(Self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<N> FileItemTreeId<N> {
|
||||
pub fn index(&self) -> Idx<N> {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl<N> Clone for FileItemTreeId<N> {
|
||||
fn clone(&self) -> Self {
|
||||
*self
|
||||
}
|
||||
}
|
||||
impl<N> Copy for FileItemTreeId<N> {}
|
||||
|
||||
impl<N> PartialEq for FileItemTreeId<N> {
|
||||
fn eq(&self, other: &FileItemTreeId<N>) -> bool {
|
||||
self.0 == other.0
|
||||
}
|
||||
}
|
||||
impl<N> Eq for FileItemTreeId<N> {}
|
||||
|
||||
impl<N> Hash for FileItemTreeId<N> {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
self.0.hash(state)
|
||||
}
|
||||
}
|
||||
|
||||
impl<N> fmt::Debug for FileItemTreeId<N> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
self.0.fmt(f)
|
||||
}
|
||||
}
|
||||
#[allow(type_alias_bounds)]
|
||||
pub type ItemTreeAstId<T: ItemTreeNode> = FileAstId<T::Source>;
|
||||
|
||||
/// Identifies a particular [`ItemTree`].
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
|
||||
@ -409,21 +369,21 @@ macro_rules! mod_items {
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
|
||||
pub enum ModItem {
|
||||
$(
|
||||
$typ(FileItemTreeId<$typ>),
|
||||
$typ(FileAstId<$ast>),
|
||||
)+
|
||||
}
|
||||
|
||||
impl ModItem {
|
||||
pub fn ast_id(&self, tree: &ItemTree) -> FileAstId<ast::Item> {
|
||||
pub fn ast_id(self) -> FileAstId<ast::Item> {
|
||||
match self {
|
||||
$(ModItem::$typ(it) => tree[it.index()].ast_id().upcast()),+
|
||||
$(ModItem::$typ(it) => it.upcast()),+
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$(
|
||||
impl From<FileItemTreeId<$typ>> for ModItem {
|
||||
fn from(id: FileItemTreeId<$typ>) -> ModItem {
|
||||
impl From<FileAstId<$ast>> for ModItem {
|
||||
fn from(id: FileAstId<$ast>) -> ModItem {
|
||||
ModItem::$typ(id)
|
||||
}
|
||||
}
|
||||
@ -433,20 +393,20 @@ macro_rules! mod_items {
|
||||
impl ItemTreeNode for $typ {
|
||||
type Source = $ast;
|
||||
|
||||
fn ast_id(&self) -> FileAstId<Self::Source> {
|
||||
fn ast_id(&self) -> FileAstId<$ast> {
|
||||
self.ast_id
|
||||
}
|
||||
|
||||
fn lookup(tree: &ItemTree, index: Idx<Self>) -> &Self {
|
||||
&tree.data().$fld[index]
|
||||
fn lookup(tree: &ItemTree, index: FileAstId<$ast>) -> &Self {
|
||||
&tree.data().$fld[&index]
|
||||
}
|
||||
}
|
||||
|
||||
impl Index<Idx<$typ>> for ItemTree {
|
||||
impl Index<FileAstId<$ast>> for ItemTree {
|
||||
type Output = $typ;
|
||||
|
||||
fn index(&self, index: Idx<$typ>) -> &Self::Output {
|
||||
&self.data().$fld[index]
|
||||
fn index(&self, index: FileAstId<$ast>) -> &Self::Output {
|
||||
&self.data().$fld[&index]
|
||||
}
|
||||
}
|
||||
)+
|
||||
@ -506,13 +466,6 @@ impl Index<RawVisibilityId> for ItemTree {
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: ItemTreeNode> Index<FileItemTreeId<N>> for ItemTree {
|
||||
type Output = N;
|
||||
fn index(&self, id: FileItemTreeId<N>) -> &N {
|
||||
N::lookup(self, id.index())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
pub struct Use {
|
||||
pub visibility: RawVisibilityId,
|
||||
|
@ -20,18 +20,14 @@ use triomphe::Arc;
|
||||
use crate::{
|
||||
db::DefDatabase,
|
||||
item_tree::{
|
||||
AttrOwner, Const, Enum, ExternBlock, ExternCrate, FieldsShape, FileItemTreeId, Function,
|
||||
Idx, Impl, ImportAlias, Interned, ItemTree, ItemTreeData, Macro2, MacroCall, MacroRules,
|
||||
Mod, ModItem, ModKind, ModPath, RawAttrs, RawVisibility, RawVisibilityId, Static, Struct,
|
||||
AttrOwner, Const, Enum, ExternBlock, ExternCrate, FieldsShape, Function, Impl, ImportAlias,
|
||||
Interned, ItemTree, ItemTreeAstId, ItemTreeData, Macro2, MacroCall, MacroRules, Mod,
|
||||
ModItem, ModKind, ModPath, RawAttrs, RawVisibility, RawVisibilityId, Static, Struct,
|
||||
StructKind, Trait, TraitAlias, TypeAlias, Union, Use, UseTree, UseTreeKind,
|
||||
VisibilityExplicitness,
|
||||
},
|
||||
};
|
||||
|
||||
fn id<N>(index: Idx<N>) -> FileItemTreeId<N> {
|
||||
FileItemTreeId(index)
|
||||
}
|
||||
|
||||
pub(super) struct Ctx<'a> {
|
||||
db: &'a dyn DefDatabase,
|
||||
tree: ItemTree,
|
||||
@ -173,36 +169,36 @@ impl<'a> Ctx<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
fn lower_struct(&mut self, strukt: &ast::Struct) -> Option<FileItemTreeId<Struct>> {
|
||||
fn lower_struct(&mut self, strukt: &ast::Struct) -> Option<ItemTreeAstId<Struct>> {
|
||||
let visibility = self.lower_visibility(strukt);
|
||||
let name = strukt.name()?.as_name();
|
||||
let ast_id = self.source_ast_id_map.ast_id(strukt);
|
||||
let shape = adt_shape(strukt.kind());
|
||||
let res = Struct { name, visibility, shape, ast_id };
|
||||
let id = id(self.data().structs.alloc(res));
|
||||
self.data().structs.insert(ast_id, res);
|
||||
|
||||
Some(id)
|
||||
Some(ast_id)
|
||||
}
|
||||
|
||||
fn lower_union(&mut self, union: &ast::Union) -> Option<FileItemTreeId<Union>> {
|
||||
fn lower_union(&mut self, union: &ast::Union) -> Option<ItemTreeAstId<Union>> {
|
||||
let visibility = self.lower_visibility(union);
|
||||
let name = union.name()?.as_name();
|
||||
let ast_id = self.source_ast_id_map.ast_id(union);
|
||||
let res = Union { name, visibility, ast_id };
|
||||
let id = id(self.data().unions.alloc(res));
|
||||
Some(id)
|
||||
self.data().unions.insert(ast_id, res);
|
||||
Some(ast_id)
|
||||
}
|
||||
|
||||
fn lower_enum(&mut self, enum_: &ast::Enum) -> Option<FileItemTreeId<Enum>> {
|
||||
fn lower_enum(&mut self, enum_: &ast::Enum) -> Option<ItemTreeAstId<Enum>> {
|
||||
let visibility = self.lower_visibility(enum_);
|
||||
let name = enum_.name()?.as_name();
|
||||
let ast_id = self.source_ast_id_map.ast_id(enum_);
|
||||
let res = Enum { name, visibility, ast_id };
|
||||
let id = id(self.data().enums.alloc(res));
|
||||
Some(id)
|
||||
self.data().enums.insert(ast_id, res);
|
||||
Some(ast_id)
|
||||
}
|
||||
|
||||
fn lower_function(&mut self, func: &ast::Fn) -> Option<FileItemTreeId<Function>> {
|
||||
fn lower_function(&mut self, func: &ast::Fn) -> Option<ItemTreeAstId<Function>> {
|
||||
let visibility = self.lower_visibility(func);
|
||||
let name = func.name()?.as_name();
|
||||
|
||||
@ -210,39 +206,41 @@ impl<'a> Ctx<'a> {
|
||||
|
||||
let res = Function { name, visibility, ast_id };
|
||||
|
||||
let id = id(self.data().functions.alloc(res));
|
||||
Some(id)
|
||||
self.data().functions.insert(ast_id, res);
|
||||
Some(ast_id)
|
||||
}
|
||||
|
||||
fn lower_type_alias(
|
||||
&mut self,
|
||||
type_alias: &ast::TypeAlias,
|
||||
) -> Option<FileItemTreeId<TypeAlias>> {
|
||||
) -> Option<ItemTreeAstId<TypeAlias>> {
|
||||
let name = type_alias.name()?.as_name();
|
||||
let visibility = self.lower_visibility(type_alias);
|
||||
let ast_id = self.source_ast_id_map.ast_id(type_alias);
|
||||
let res = TypeAlias { name, visibility, ast_id };
|
||||
let id = id(self.data().type_aliases.alloc(res));
|
||||
Some(id)
|
||||
self.data().type_aliases.insert(ast_id, res);
|
||||
Some(ast_id)
|
||||
}
|
||||
|
||||
fn lower_static(&mut self, static_: &ast::Static) -> Option<FileItemTreeId<Static>> {
|
||||
fn lower_static(&mut self, static_: &ast::Static) -> Option<ItemTreeAstId<Static>> {
|
||||
let name = static_.name()?.as_name();
|
||||
let visibility = self.lower_visibility(static_);
|
||||
let ast_id = self.source_ast_id_map.ast_id(static_);
|
||||
let res = Static { name, visibility, ast_id };
|
||||
Some(id(self.data().statics.alloc(res)))
|
||||
self.data().statics.insert(ast_id, res);
|
||||
Some(ast_id)
|
||||
}
|
||||
|
||||
fn lower_const(&mut self, konst: &ast::Const) -> FileItemTreeId<Const> {
|
||||
fn lower_const(&mut self, konst: &ast::Const) -> ItemTreeAstId<Const> {
|
||||
let name = konst.name().map(|it| it.as_name());
|
||||
let visibility = self.lower_visibility(konst);
|
||||
let ast_id = self.source_ast_id_map.ast_id(konst);
|
||||
let res = Const { name, visibility, ast_id };
|
||||
id(self.data().consts.alloc(res))
|
||||
self.data().consts.insert(ast_id, res);
|
||||
ast_id
|
||||
}
|
||||
|
||||
fn lower_module(&mut self, module: &ast::Module) -> Option<FileItemTreeId<Mod>> {
|
||||
fn lower_module(&mut self, module: &ast::Module) -> Option<ItemTreeAstId<Mod>> {
|
||||
let name = module.name()?.as_name();
|
||||
let visibility = self.lower_visibility(module);
|
||||
let kind = if module.semicolon_token().is_some() {
|
||||
@ -260,41 +258,43 @@ impl<'a> Ctx<'a> {
|
||||
};
|
||||
let ast_id = self.source_ast_id_map.ast_id(module);
|
||||
let res = Mod { name, visibility, kind, ast_id };
|
||||
Some(id(self.data().mods.alloc(res)))
|
||||
self.data().mods.insert(ast_id, res);
|
||||
Some(ast_id)
|
||||
}
|
||||
|
||||
fn lower_trait(&mut self, trait_def: &ast::Trait) -> Option<FileItemTreeId<Trait>> {
|
||||
fn lower_trait(&mut self, trait_def: &ast::Trait) -> Option<ItemTreeAstId<Trait>> {
|
||||
let name = trait_def.name()?.as_name();
|
||||
let visibility = self.lower_visibility(trait_def);
|
||||
let ast_id = self.source_ast_id_map.ast_id(trait_def);
|
||||
|
||||
let def = Trait { name, visibility, ast_id };
|
||||
let id = id(self.data().traits.alloc(def));
|
||||
Some(id)
|
||||
self.data().traits.insert(ast_id, def);
|
||||
Some(ast_id)
|
||||
}
|
||||
|
||||
fn lower_trait_alias(
|
||||
&mut self,
|
||||
trait_alias_def: &ast::TraitAlias,
|
||||
) -> Option<FileItemTreeId<TraitAlias>> {
|
||||
) -> Option<ItemTreeAstId<TraitAlias>> {
|
||||
let name = trait_alias_def.name()?.as_name();
|
||||
let visibility = self.lower_visibility(trait_alias_def);
|
||||
let ast_id = self.source_ast_id_map.ast_id(trait_alias_def);
|
||||
|
||||
let alias = TraitAlias { name, visibility, ast_id };
|
||||
let id = id(self.data().trait_aliases.alloc(alias));
|
||||
Some(id)
|
||||
self.data().trait_aliases.insert(ast_id, alias);
|
||||
Some(ast_id)
|
||||
}
|
||||
|
||||
fn lower_impl(&mut self, impl_def: &ast::Impl) -> FileItemTreeId<Impl> {
|
||||
fn lower_impl(&mut self, impl_def: &ast::Impl) -> ItemTreeAstId<Impl> {
|
||||
let ast_id = self.source_ast_id_map.ast_id(impl_def);
|
||||
// Note that trait impls don't get implicit `Self` unlike traits, because here they are a
|
||||
// type alias rather than a type parameter, so this is handled by the resolver.
|
||||
let res = Impl { ast_id };
|
||||
id(self.data().impls.alloc(res))
|
||||
self.data().impls.insert(ast_id, res);
|
||||
ast_id
|
||||
}
|
||||
|
||||
fn lower_use(&mut self, use_item: &ast::Use) -> Option<FileItemTreeId<Use>> {
|
||||
fn lower_use(&mut self, use_item: &ast::Use) -> Option<ItemTreeAstId<Use>> {
|
||||
let visibility = self.lower_visibility(use_item);
|
||||
let ast_id = self.source_ast_id_map.ast_id(use_item);
|
||||
let (use_tree, _) = lower_use_tree(self.db, use_item.use_tree()?, &mut |range| {
|
||||
@ -302,13 +302,14 @@ impl<'a> Ctx<'a> {
|
||||
})?;
|
||||
|
||||
let res = Use { visibility, ast_id, use_tree };
|
||||
Some(id(self.data().uses.alloc(res)))
|
||||
self.data().uses.insert(ast_id, res);
|
||||
Some(ast_id)
|
||||
}
|
||||
|
||||
fn lower_extern_crate(
|
||||
&mut self,
|
||||
extern_crate: &ast::ExternCrate,
|
||||
) -> Option<FileItemTreeId<ExternCrate>> {
|
||||
) -> Option<ItemTreeAstId<ExternCrate>> {
|
||||
let name = extern_crate.name_ref()?.as_name();
|
||||
let alias = extern_crate.rename().map(|a| {
|
||||
a.name().map(|it| it.as_name()).map_or(ImportAlias::Underscore, ImportAlias::Alias)
|
||||
@ -317,10 +318,11 @@ impl<'a> Ctx<'a> {
|
||||
let ast_id = self.source_ast_id_map.ast_id(extern_crate);
|
||||
|
||||
let res = ExternCrate { name, alias, visibility, ast_id };
|
||||
Some(id(self.data().extern_crates.alloc(res)))
|
||||
self.data().extern_crates.insert(ast_id, res);
|
||||
Some(ast_id)
|
||||
}
|
||||
|
||||
fn lower_macro_call(&mut self, m: &ast::MacroCall) -> Option<FileItemTreeId<MacroCall>> {
|
||||
fn lower_macro_call(&mut self, m: &ast::MacroCall) -> Option<ItemTreeAstId<MacroCall>> {
|
||||
let span_map = self.span_map();
|
||||
let path = m.path()?;
|
||||
let range = path.syntax().text_range();
|
||||
@ -330,28 +332,31 @@ impl<'a> Ctx<'a> {
|
||||
let ast_id = self.source_ast_id_map.ast_id(m);
|
||||
let expand_to = hir_expand::ExpandTo::from_call_site(m);
|
||||
let res = MacroCall { path, ast_id, expand_to, ctxt: span_map.span_for_range(range).ctx };
|
||||
Some(id(self.data().macro_calls.alloc(res)))
|
||||
self.data().macro_calls.insert(ast_id, res);
|
||||
Some(ast_id)
|
||||
}
|
||||
|
||||
fn lower_macro_rules(&mut self, m: &ast::MacroRules) -> Option<FileItemTreeId<MacroRules>> {
|
||||
fn lower_macro_rules(&mut self, m: &ast::MacroRules) -> Option<ItemTreeAstId<MacroRules>> {
|
||||
let name = m.name()?;
|
||||
let ast_id = self.source_ast_id_map.ast_id(m);
|
||||
|
||||
let res = MacroRules { name: name.as_name(), ast_id };
|
||||
Some(id(self.data().macro_rules.alloc(res)))
|
||||
self.data().macro_rules.insert(ast_id, res);
|
||||
Some(ast_id)
|
||||
}
|
||||
|
||||
fn lower_macro_def(&mut self, m: &ast::MacroDef) -> Option<FileItemTreeId<Macro2>> {
|
||||
fn lower_macro_def(&mut self, m: &ast::MacroDef) -> Option<ItemTreeAstId<Macro2>> {
|
||||
let name = m.name()?;
|
||||
|
||||
let ast_id = self.source_ast_id_map.ast_id(m);
|
||||
let visibility = self.lower_visibility(m);
|
||||
|
||||
let res = Macro2 { name: name.as_name(), ast_id, visibility };
|
||||
Some(id(self.data().macro_defs.alloc(res)))
|
||||
self.data().macro_defs.insert(ast_id, res);
|
||||
Some(ast_id)
|
||||
}
|
||||
|
||||
fn lower_extern_block(&mut self, block: &ast::ExternBlock) -> FileItemTreeId<ExternBlock> {
|
||||
fn lower_extern_block(&mut self, block: &ast::ExternBlock) -> ItemTreeAstId<ExternBlock> {
|
||||
let ast_id = self.source_ast_id_map.ast_id(block);
|
||||
let children: Box<[_]> = block.extern_item_list().map_or(Box::new([]), |list| {
|
||||
list.extern_items()
|
||||
@ -374,7 +379,8 @@ impl<'a> Ctx<'a> {
|
||||
});
|
||||
|
||||
let res = ExternBlock { ast_id, children };
|
||||
id(self.data().extern_blocks.alloc(res))
|
||||
self.data().extern_blocks.insert(ast_id, res);
|
||||
ast_id
|
||||
}
|
||||
|
||||
fn lower_visibility(&mut self, item: &dyn ast::HasVisibility) -> RawVisibilityId {
|
||||
|
@ -80,7 +80,7 @@ use crate::{
|
||||
LocalModuleId, Lookup, MacroExpander, MacroId, ModuleId, ProcMacroId, UseId,
|
||||
db::DefDatabase,
|
||||
item_scope::{BuiltinShadowMode, ItemScope},
|
||||
item_tree::{FileItemTreeId, Mod, TreeId},
|
||||
item_tree::TreeId,
|
||||
nameres::{diagnostics::DefDiagnostic, path_resolution::ResolveMode},
|
||||
per_ns::PerNs,
|
||||
visibility::{Visibility, VisibilityExplicitness},
|
||||
@ -290,12 +290,10 @@ pub enum ModuleOrigin {
|
||||
is_mod_rs: bool,
|
||||
declaration: FileAstId<ast::Module>,
|
||||
declaration_tree_id: TreeId,
|
||||
file_item_tree_id: FileItemTreeId<Mod>,
|
||||
definition: EditionedFileId,
|
||||
},
|
||||
Inline {
|
||||
definition_tree_id: TreeId,
|
||||
file_item_tree_id: FileItemTreeId<Mod>,
|
||||
definition: FileAstId<ast::Module>,
|
||||
},
|
||||
/// Pseudo-module introduced by a block scope (contains only inner items).
|
||||
@ -311,7 +309,7 @@ impl ModuleOrigin {
|
||||
&ModuleOrigin::File { declaration, declaration_tree_id, .. } => {
|
||||
Some(AstId::new(declaration_tree_id.file_id(), declaration))
|
||||
}
|
||||
&ModuleOrigin::Inline { definition, definition_tree_id, file_item_tree_id: _ } => {
|
||||
&ModuleOrigin::Inline { definition, definition_tree_id } => {
|
||||
Some(AstId::new(definition_tree_id.file_id(), definition))
|
||||
}
|
||||
ModuleOrigin::CrateRoot { .. } | ModuleOrigin::BlockExpr { .. } => None,
|
||||
@ -343,14 +341,12 @@ impl ModuleOrigin {
|
||||
let sf = db.parse(editioned_file_id).tree();
|
||||
InFile::new(editioned_file_id.into(), ModuleSource::SourceFile(sf))
|
||||
}
|
||||
&ModuleOrigin::Inline { definition, definition_tree_id, file_item_tree_id: _ } => {
|
||||
InFile::new(
|
||||
definition_tree_id.file_id(),
|
||||
ModuleSource::Module(
|
||||
AstId::new(definition_tree_id.file_id(), definition).to_node(db),
|
||||
),
|
||||
)
|
||||
}
|
||||
&ModuleOrigin::Inline { definition, definition_tree_id } => InFile::new(
|
||||
definition_tree_id.file_id(),
|
||||
ModuleSource::Module(
|
||||
AstId::new(definition_tree_id.file_id(), definition).to_node(db),
|
||||
),
|
||||
),
|
||||
ModuleOrigin::BlockExpr { block, .. } => {
|
||||
InFile::new(block.file_id, ModuleSource::BlockExpr(block.to_node(db)))
|
||||
}
|
||||
@ -777,12 +773,10 @@ impl ModuleData {
|
||||
ErasedAstId::new(definition.into(), ROOT_ERASED_FILE_AST_ID).to_range(db),
|
||||
)
|
||||
}
|
||||
&ModuleOrigin::Inline { definition, definition_tree_id, file_item_tree_id: _ } => {
|
||||
InFile::new(
|
||||
definition_tree_id.file_id(),
|
||||
AstId::new(definition_tree_id.file_id(), definition).to_range(db),
|
||||
)
|
||||
}
|
||||
&ModuleOrigin::Inline { definition, definition_tree_id } => InFile::new(
|
||||
definition_tree_id.file_id(),
|
||||
AstId::new(definition_tree_id.file_id(), definition).to_range(db),
|
||||
),
|
||||
ModuleOrigin::BlockExpr { block, .. } => InFile::new(block.file_id, block.to_range(db)),
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ use crate::{
|
||||
db::DefDatabase,
|
||||
item_scope::{GlobId, ImportId, ImportOrExternCrate, PerNsGlobImports},
|
||||
item_tree::{
|
||||
self, FieldsShape, FileItemTreeId, ImportAlias, ImportKind, ItemTree, ItemTreeNode, Macro2,
|
||||
self, FieldsShape, ImportAlias, ImportKind, ItemTree, ItemTreeAstId, ItemTreeNode, Macro2,
|
||||
MacroCall, MacroRules, Mod, ModItem, ModKind, TreeId, UseTreeKind,
|
||||
},
|
||||
macro_call_as_call_id,
|
||||
@ -141,7 +141,7 @@ struct ImportSource {
|
||||
is_prelude: bool,
|
||||
kind: ImportKind,
|
||||
tree: TreeId,
|
||||
item: FileItemTreeId<item_tree::Use>,
|
||||
item: FileAstId<ast::Use>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
@ -156,7 +156,7 @@ impl Import {
|
||||
fn from_use(
|
||||
tree: &ItemTree,
|
||||
tree_id: TreeId,
|
||||
item: FileItemTreeId<item_tree::Use>,
|
||||
item: FileAstId<ast::Use>,
|
||||
id: UseId,
|
||||
is_prelude: bool,
|
||||
mut cb: impl FnMut(Self),
|
||||
@ -2084,7 +2084,7 @@ impl ModCollector<'_, '_> {
|
||||
);
|
||||
}
|
||||
|
||||
fn collect_module(&mut self, module_id: FileItemTreeId<Mod>, attrs: &Attrs) {
|
||||
fn collect_module(&mut self, module_id: ItemTreeAstId<Mod>, attrs: &Attrs) {
|
||||
let path_attr = attrs.by_key(sym::path).string_value_unescape();
|
||||
let is_macro_use = attrs.by_key(sym::macro_use).exists();
|
||||
let module = &self.item_tree[module_id];
|
||||
@ -2096,7 +2096,6 @@ impl ModCollector<'_, '_> {
|
||||
module.ast_id,
|
||||
None,
|
||||
&self.item_tree[module.visibility],
|
||||
module_id,
|
||||
);
|
||||
|
||||
let Some(mod_dir) =
|
||||
@ -2151,7 +2150,6 @@ impl ModCollector<'_, '_> {
|
||||
ast_id.value,
|
||||
Some((file_id, is_mod_rs)),
|
||||
&self.item_tree[module.visibility],
|
||||
module_id,
|
||||
);
|
||||
ModCollector {
|
||||
def_collector: self.def_collector,
|
||||
@ -2179,7 +2177,6 @@ impl ModCollector<'_, '_> {
|
||||
ast_id.value,
|
||||
None,
|
||||
&self.item_tree[module.visibility],
|
||||
module_id,
|
||||
);
|
||||
self.def_collector.def_map.diagnostics.push(
|
||||
DefDiagnostic::unresolved_module(self.module_id, ast_id, candidates),
|
||||
@ -2196,7 +2193,6 @@ impl ModCollector<'_, '_> {
|
||||
declaration: FileAstId<ast::Module>,
|
||||
definition: Option<(EditionedFileId, bool)>,
|
||||
visibility: &crate::visibility::RawVisibility,
|
||||
mod_tree_id: FileItemTreeId<Mod>,
|
||||
) -> LocalModuleId {
|
||||
let def_map = &mut self.def_collector.def_map;
|
||||
let vis = def_map
|
||||
@ -2209,17 +2205,14 @@ impl ModCollector<'_, '_> {
|
||||
)
|
||||
.unwrap_or(Visibility::Public);
|
||||
let origin = match definition {
|
||||
None => ModuleOrigin::Inline {
|
||||
definition: declaration,
|
||||
definition_tree_id: self.tree_id,
|
||||
file_item_tree_id: mod_tree_id,
|
||||
},
|
||||
None => {
|
||||
ModuleOrigin::Inline { definition: declaration, definition_tree_id: self.tree_id }
|
||||
}
|
||||
Some((definition, is_mod_rs)) => ModuleOrigin::File {
|
||||
declaration,
|
||||
definition,
|
||||
is_mod_rs,
|
||||
declaration_tree_id: self.tree_id,
|
||||
file_item_tree_id: mod_tree_id,
|
||||
},
|
||||
};
|
||||
|
||||
@ -2294,11 +2287,7 @@ impl ModCollector<'_, '_> {
|
||||
attr.path.display(self.def_collector.db, Edition::LATEST)
|
||||
);
|
||||
|
||||
let ast_id = AstIdWithPath::new(
|
||||
self.file_id(),
|
||||
mod_item.ast_id(self.item_tree),
|
||||
attr.path.clone(),
|
||||
);
|
||||
let ast_id = AstIdWithPath::new(self.file_id(), mod_item.ast_id(), attr.path.clone());
|
||||
self.def_collector.unresolved_macros.push(MacroDirective {
|
||||
module_id: self.module_id,
|
||||
depth: self.macro_depth + 1,
|
||||
@ -2317,7 +2306,7 @@ impl ModCollector<'_, '_> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn collect_macro_rules(&mut self, id: FileItemTreeId<MacroRules>, module: ModuleId) {
|
||||
fn collect_macro_rules(&mut self, id: ItemTreeAstId<MacroRules>, module: ModuleId) {
|
||||
let krate = self.def_collector.def_map.krate;
|
||||
let mac = &self.item_tree[id];
|
||||
let attrs = self.item_tree.attrs(self.def_collector.db, krate, ModItem::from(id).into());
|
||||
@ -2402,7 +2391,7 @@ impl ModCollector<'_, '_> {
|
||||
);
|
||||
}
|
||||
|
||||
fn collect_macro_def(&mut self, id: FileItemTreeId<Macro2>, module: ModuleId) {
|
||||
fn collect_macro_def(&mut self, id: ItemTreeAstId<Macro2>, module: ModuleId) {
|
||||
let krate = self.def_collector.def_map.krate;
|
||||
let mac = &self.item_tree[id];
|
||||
let ast_id = InFile::new(self.file_id(), mac.ast_id.upcast());
|
||||
|
Loading…
x
Reference in New Issue
Block a user