mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
Remove ast ids from item tree mod items
This commit is contained in:
parent
65e2e2c083
commit
048a01a05d
@ -212,13 +212,13 @@ impl ItemTree {
|
||||
SmallModItem::Trait(_) => traits += 1,
|
||||
SmallModItem::Impl(_) => impls += 1,
|
||||
SmallModItem::MacroRules(_) => macro_rules += 1,
|
||||
SmallModItem::MacroCall(_) => macro_calls += 1,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
for item in self.big_data.values() {
|
||||
match item {
|
||||
BigModItem::Mod(_) => mods += 1,
|
||||
BigModItem::MacroCall(_) => macro_calls += 1,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
@ -246,11 +246,14 @@ struct ItemVisibilities {
|
||||
enum SmallModItem {
|
||||
Const(Const),
|
||||
Enum(Enum),
|
||||
ExternBlock(ExternBlock),
|
||||
Function(Function),
|
||||
Impl(Impl),
|
||||
Macro2(Macro2),
|
||||
MacroCall(MacroCall),
|
||||
MacroRules(MacroRules),
|
||||
Static(Static),
|
||||
Struct(Struct),
|
||||
Trait(Trait),
|
||||
TraitAlias(TraitAlias),
|
||||
TypeAlias(TypeAlias),
|
||||
@ -259,11 +262,8 @@ enum SmallModItem {
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
enum BigModItem {
|
||||
ExternBlock(ExternBlock),
|
||||
ExternCrate(ExternCrate),
|
||||
MacroCall(MacroCall),
|
||||
Mod(Mod),
|
||||
Struct(Struct),
|
||||
Use(Use),
|
||||
}
|
||||
|
||||
@ -370,23 +370,23 @@ macro_rules! mod_items {
|
||||
|
||||
mod_items! {
|
||||
ModItemId ->
|
||||
Use in big_data -> ast::Use,
|
||||
ExternCrate in big_data -> ast::ExternCrate,
|
||||
ExternBlock in big_data -> ast::ExternBlock,
|
||||
Function in small_data -> ast::Fn,
|
||||
Struct in big_data -> ast::Struct,
|
||||
Union in small_data -> ast::Union,
|
||||
Enum in small_data -> ast::Enum,
|
||||
Const in small_data -> ast::Const,
|
||||
Enum in small_data -> ast::Enum,
|
||||
ExternBlock in small_data -> ast::ExternBlock,
|
||||
ExternCrate in big_data -> ast::ExternCrate,
|
||||
Function in small_data -> ast::Fn,
|
||||
Impl in small_data -> ast::Impl,
|
||||
Macro2 in small_data -> ast::MacroDef,
|
||||
MacroCall in small_data -> ast::MacroCall,
|
||||
MacroRules in small_data -> ast::MacroRules,
|
||||
Mod in big_data -> ast::Module,
|
||||
Static in small_data -> ast::Static,
|
||||
Struct in small_data -> ast::Struct,
|
||||
Trait in small_data -> ast::Trait,
|
||||
TraitAlias in small_data -> ast::TraitAlias,
|
||||
Impl in small_data -> ast::Impl,
|
||||
TypeAlias in small_data -> ast::TypeAlias,
|
||||
Mod in big_data -> ast::Module,
|
||||
MacroCall in big_data -> ast::MacroCall,
|
||||
MacroRules in small_data -> ast::MacroRules,
|
||||
Macro2 in small_data -> ast::MacroDef,
|
||||
Union in small_data -> ast::Union,
|
||||
Use in big_data -> ast::Use,
|
||||
}
|
||||
|
||||
impl Index<RawVisibilityId> for ItemTree {
|
||||
@ -425,7 +425,6 @@ impl Index<RawVisibilityId> for ItemTree {
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
pub struct Use {
|
||||
pub(crate) visibility: RawVisibilityId,
|
||||
pub(crate) ast_id: FileAstId<ast::Use>,
|
||||
pub(crate) use_tree: UseTree,
|
||||
}
|
||||
|
||||
@ -490,12 +489,10 @@ pub struct ExternCrate {
|
||||
pub name: Name,
|
||||
pub alias: Option<ImportAlias>,
|
||||
pub(crate) visibility: RawVisibilityId,
|
||||
pub ast_id: FileAstId<ast::ExternCrate>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
pub struct ExternBlock {
|
||||
pub ast_id: FileAstId<ast::ExternBlock>,
|
||||
pub(crate) children: Box<[ModItemId]>,
|
||||
}
|
||||
|
||||
@ -503,7 +500,6 @@ pub struct ExternBlock {
|
||||
pub struct Function {
|
||||
pub name: Name,
|
||||
pub(crate) visibility: RawVisibilityId,
|
||||
pub ast_id: FileAstId<ast::Fn>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
@ -511,21 +507,18 @@ pub struct Struct {
|
||||
pub name: Name,
|
||||
pub(crate) visibility: RawVisibilityId,
|
||||
pub shape: FieldsShape,
|
||||
pub ast_id: FileAstId<ast::Struct>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
pub struct Union {
|
||||
pub name: Name,
|
||||
pub(crate) visibility: RawVisibilityId,
|
||||
pub ast_id: FileAstId<ast::Union>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
pub struct Enum {
|
||||
pub name: Name,
|
||||
pub(crate) visibility: RawVisibilityId,
|
||||
pub ast_id: FileAstId<ast::Enum>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
@ -564,40 +557,33 @@ pub struct Const {
|
||||
/// `None` for `const _: () = ();`
|
||||
pub name: Option<Name>,
|
||||
pub(crate) visibility: RawVisibilityId,
|
||||
pub ast_id: FileAstId<ast::Const>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
pub struct Static {
|
||||
pub name: Name,
|
||||
pub(crate) visibility: RawVisibilityId,
|
||||
pub ast_id: FileAstId<ast::Static>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
pub struct Trait {
|
||||
pub name: Name,
|
||||
pub(crate) visibility: RawVisibilityId,
|
||||
pub ast_id: FileAstId<ast::Trait>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
pub struct TraitAlias {
|
||||
pub name: Name,
|
||||
pub(crate) visibility: RawVisibilityId,
|
||||
pub ast_id: FileAstId<ast::TraitAlias>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
pub struct Impl {
|
||||
pub ast_id: FileAstId<ast::Impl>,
|
||||
}
|
||||
pub struct Impl {}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct TypeAlias {
|
||||
pub name: Name,
|
||||
pub(crate) visibility: RawVisibilityId,
|
||||
pub ast_id: FileAstId<ast::TypeAlias>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
@ -605,7 +591,6 @@ pub struct Mod {
|
||||
pub name: Name,
|
||||
pub(crate) visibility: RawVisibilityId,
|
||||
pub(crate) kind: ModKind,
|
||||
pub ast_id: FileAstId<ast::Module>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
@ -620,7 +605,6 @@ pub(crate) enum ModKind {
|
||||
pub struct MacroCall {
|
||||
/// Path to the called macro.
|
||||
pub path: Interned<ModPath>,
|
||||
pub ast_id: FileAstId<ast::MacroCall>,
|
||||
pub expand_to: ExpandTo,
|
||||
pub ctxt: SyntaxContext,
|
||||
}
|
||||
@ -629,7 +613,6 @@ pub struct MacroCall {
|
||||
pub struct MacroRules {
|
||||
/// The name of the declared macro.
|
||||
pub name: Name,
|
||||
pub ast_id: FileAstId<ast::MacroRules>,
|
||||
}
|
||||
|
||||
/// "Macros 2.0" macro definition.
|
||||
@ -637,7 +620,6 @@ pub struct MacroRules {
|
||||
pub struct Macro2 {
|
||||
pub name: Name,
|
||||
pub(crate) visibility: RawVisibilityId,
|
||||
pub ast_id: FileAstId<ast::MacroDef>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
|
@ -168,8 +168,8 @@ impl<'a> Ctx<'a> {
|
||||
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 };
|
||||
self.tree.big_data.insert(ast_id.upcast(), BigModItem::Struct(res));
|
||||
let res = Struct { name, visibility, shape };
|
||||
self.tree.small_data.insert(ast_id.upcast(), SmallModItem::Struct(res));
|
||||
|
||||
Some(ast_id)
|
||||
}
|
||||
@ -178,7 +178,7 @@ impl<'a> Ctx<'a> {
|
||||
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 res = Union { name, visibility };
|
||||
self.tree.small_data.insert(ast_id.upcast(), SmallModItem::Union(res));
|
||||
Some(ast_id)
|
||||
}
|
||||
@ -187,7 +187,7 @@ impl<'a> Ctx<'a> {
|
||||
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 res = Enum { name, visibility };
|
||||
self.tree.small_data.insert(ast_id.upcast(), SmallModItem::Enum(res));
|
||||
Some(ast_id)
|
||||
}
|
||||
@ -198,7 +198,7 @@ impl<'a> Ctx<'a> {
|
||||
|
||||
let ast_id = self.source_ast_id_map.ast_id(func);
|
||||
|
||||
let res = Function { name, visibility, ast_id };
|
||||
let res = Function { name, visibility };
|
||||
|
||||
self.tree.small_data.insert(ast_id.upcast(), SmallModItem::Function(res));
|
||||
Some(ast_id)
|
||||
@ -211,7 +211,7 @@ impl<'a> Ctx<'a> {
|
||||
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 res = TypeAlias { name, visibility };
|
||||
self.tree.small_data.insert(ast_id.upcast(), SmallModItem::TypeAlias(res));
|
||||
Some(ast_id)
|
||||
}
|
||||
@ -220,7 +220,7 @@ impl<'a> Ctx<'a> {
|
||||
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 };
|
||||
let res = Static { name, visibility };
|
||||
self.tree.small_data.insert(ast_id.upcast(), SmallModItem::Static(res));
|
||||
Some(ast_id)
|
||||
}
|
||||
@ -229,7 +229,7 @@ impl<'a> Ctx<'a> {
|
||||
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 };
|
||||
let res = Const { name, visibility };
|
||||
self.tree.small_data.insert(ast_id.upcast(), SmallModItem::Const(res));
|
||||
ast_id
|
||||
}
|
||||
@ -251,7 +251,7 @@ impl<'a> Ctx<'a> {
|
||||
}
|
||||
};
|
||||
let ast_id = self.source_ast_id_map.ast_id(module);
|
||||
let res = Mod { name, visibility, kind, ast_id };
|
||||
let res = Mod { name, visibility, kind };
|
||||
self.tree.big_data.insert(ast_id.upcast(), BigModItem::Mod(res));
|
||||
Some(ast_id)
|
||||
}
|
||||
@ -261,7 +261,7 @@ impl<'a> Ctx<'a> {
|
||||
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 def = Trait { name, visibility };
|
||||
self.tree.small_data.insert(ast_id.upcast(), SmallModItem::Trait(def));
|
||||
Some(ast_id)
|
||||
}
|
||||
@ -274,7 +274,7 @@ impl<'a> Ctx<'a> {
|
||||
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 alias = TraitAlias { name, visibility };
|
||||
self.tree.small_data.insert(ast_id.upcast(), SmallModItem::TraitAlias(alias));
|
||||
Some(ast_id)
|
||||
}
|
||||
@ -283,7 +283,7 @@ impl<'a> Ctx<'a> {
|
||||
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 };
|
||||
let res = Impl {};
|
||||
self.tree.small_data.insert(ast_id.upcast(), SmallModItem::Impl(res));
|
||||
ast_id
|
||||
}
|
||||
@ -295,7 +295,7 @@ impl<'a> Ctx<'a> {
|
||||
self.span_map().span_for_range(range).ctx
|
||||
})?;
|
||||
|
||||
let res = Use { visibility, ast_id, use_tree };
|
||||
let res = Use { visibility, use_tree };
|
||||
self.tree.big_data.insert(ast_id.upcast(), BigModItem::Use(res));
|
||||
Some(ast_id)
|
||||
}
|
||||
@ -311,7 +311,7 @@ impl<'a> Ctx<'a> {
|
||||
let visibility = self.lower_visibility(extern_crate);
|
||||
let ast_id = self.source_ast_id_map.ast_id(extern_crate);
|
||||
|
||||
let res = ExternCrate { name, alias, visibility, ast_id };
|
||||
let res = ExternCrate { name, alias, visibility };
|
||||
self.tree.big_data.insert(ast_id.upcast(), BigModItem::ExternCrate(res));
|
||||
Some(ast_id)
|
||||
}
|
||||
@ -325,8 +325,8 @@ 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 };
|
||||
self.tree.big_data.insert(ast_id.upcast(), BigModItem::MacroCall(res));
|
||||
let res = MacroCall { path, expand_to, ctxt: span_map.span_for_range(range).ctx };
|
||||
self.tree.small_data.insert(ast_id.upcast(), SmallModItem::MacroCall(res));
|
||||
Some(ast_id)
|
||||
}
|
||||
|
||||
@ -334,7 +334,7 @@ impl<'a> Ctx<'a> {
|
||||
let name = m.name()?;
|
||||
let ast_id = self.source_ast_id_map.ast_id(m);
|
||||
|
||||
let res = MacroRules { name: name.as_name(), ast_id };
|
||||
let res = MacroRules { name: name.as_name() };
|
||||
self.tree.small_data.insert(ast_id.upcast(), SmallModItem::MacroRules(res));
|
||||
Some(ast_id)
|
||||
}
|
||||
@ -345,7 +345,7 @@ impl<'a> Ctx<'a> {
|
||||
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 };
|
||||
let res = Macro2 { name: name.as_name(), visibility };
|
||||
self.tree.small_data.insert(ast_id.upcast(), SmallModItem::Macro2(res));
|
||||
Some(ast_id)
|
||||
}
|
||||
@ -372,8 +372,8 @@ impl<'a> Ctx<'a> {
|
||||
.collect()
|
||||
});
|
||||
|
||||
let res = ExternBlock { ast_id, children };
|
||||
self.tree.big_data.insert(ast_id.upcast(), BigModItem::ExternBlock(res));
|
||||
let res = ExternBlock { children };
|
||||
self.tree.small_data.insert(ast_id.upcast(), SmallModItem::ExternBlock(res));
|
||||
ast_id
|
||||
}
|
||||
|
||||
|
@ -161,16 +161,16 @@ impl Printer<'_> {
|
||||
self.print_attrs_of(item, "\n");
|
||||
|
||||
match item {
|
||||
ModItemId::Use(it) => {
|
||||
let Use { visibility, use_tree, ast_id } = &self.tree[it];
|
||||
ModItemId::Use(ast_id) => {
|
||||
let Use { visibility, use_tree } = &self.tree[ast_id];
|
||||
self.print_ast_id(ast_id.erase());
|
||||
self.print_visibility(*visibility);
|
||||
w!(self, "use ");
|
||||
self.print_use_tree(use_tree);
|
||||
wln!(self, ";");
|
||||
}
|
||||
ModItemId::ExternCrate(it) => {
|
||||
let ExternCrate { name, alias, visibility, ast_id } = &self.tree[it];
|
||||
ModItemId::ExternCrate(ast_id) => {
|
||||
let ExternCrate { name, alias, visibility } = &self.tree[ast_id];
|
||||
self.print_ast_id(ast_id.erase());
|
||||
self.print_visibility(*visibility);
|
||||
w!(self, "extern crate {}", name.display(self.db, self.edition));
|
||||
@ -179,8 +179,8 @@ impl Printer<'_> {
|
||||
}
|
||||
wln!(self, ";");
|
||||
}
|
||||
ModItemId::ExternBlock(it) => {
|
||||
let ExternBlock { ast_id, children } = &self.tree[it];
|
||||
ModItemId::ExternBlock(ast_id) => {
|
||||
let ExternBlock { children } = &self.tree[ast_id];
|
||||
self.print_ast_id(ast_id.erase());
|
||||
w!(self, "extern {{");
|
||||
self.indented(|this| {
|
||||
@ -190,14 +190,14 @@ impl Printer<'_> {
|
||||
});
|
||||
wln!(self, "}}");
|
||||
}
|
||||
ModItemId::Function(it) => {
|
||||
let Function { name, visibility, ast_id } = &self.tree[it];
|
||||
ModItemId::Function(ast_id) => {
|
||||
let Function { name, visibility } = &self.tree[ast_id];
|
||||
self.print_ast_id(ast_id.erase());
|
||||
self.print_visibility(*visibility);
|
||||
wln!(self, "fn {};", name.display(self.db, self.edition));
|
||||
}
|
||||
ModItemId::Struct(it) => {
|
||||
let Struct { visibility, name, shape: kind, ast_id } = &self.tree[it];
|
||||
ModItemId::Struct(ast_id) => {
|
||||
let Struct { visibility, name, shape: kind } = &self.tree[ast_id];
|
||||
self.print_ast_id(ast_id.erase());
|
||||
self.print_visibility(*visibility);
|
||||
w!(self, "struct {}", name.display(self.db, self.edition));
|
||||
@ -208,22 +208,22 @@ impl Printer<'_> {
|
||||
wln!(self, ";");
|
||||
}
|
||||
}
|
||||
ModItemId::Union(it) => {
|
||||
let Union { name, visibility, ast_id } = &self.tree[it];
|
||||
ModItemId::Union(ast_id) => {
|
||||
let Union { name, visibility } = &self.tree[ast_id];
|
||||
self.print_ast_id(ast_id.erase());
|
||||
self.print_visibility(*visibility);
|
||||
w!(self, "union {}", name.display(self.db, self.edition));
|
||||
self.print_fields(FieldsShape::Record);
|
||||
wln!(self);
|
||||
}
|
||||
ModItemId::Enum(it) => {
|
||||
let Enum { name, visibility, ast_id } = &self.tree[it];
|
||||
ModItemId::Enum(ast_id) => {
|
||||
let Enum { name, visibility } = &self.tree[ast_id];
|
||||
self.print_ast_id(ast_id.erase());
|
||||
self.print_visibility(*visibility);
|
||||
w!(self, "enum {} {{ ... }}", name.display(self.db, self.edition));
|
||||
}
|
||||
ModItemId::Const(it) => {
|
||||
let Const { name, visibility, ast_id } = &self.tree[it];
|
||||
ModItemId::Const(ast_id) => {
|
||||
let Const { name, visibility } = &self.tree[ast_id];
|
||||
self.print_ast_id(ast_id.erase());
|
||||
self.print_visibility(*visibility);
|
||||
w!(self, "const ");
|
||||
@ -233,8 +233,8 @@ impl Printer<'_> {
|
||||
}
|
||||
wln!(self, " = _;");
|
||||
}
|
||||
ModItemId::Static(it) => {
|
||||
let Static { name, visibility, ast_id } = &self.tree[it];
|
||||
ModItemId::Static(ast_id) => {
|
||||
let Static { name, visibility } = &self.tree[ast_id];
|
||||
self.print_ast_id(ast_id.erase());
|
||||
self.print_visibility(*visibility);
|
||||
w!(self, "static ");
|
||||
@ -242,33 +242,33 @@ impl Printer<'_> {
|
||||
w!(self, " = _;");
|
||||
wln!(self);
|
||||
}
|
||||
ModItemId::Trait(it) => {
|
||||
let Trait { name, visibility, ast_id } = &self.tree[it];
|
||||
ModItemId::Trait(ast_id) => {
|
||||
let Trait { name, visibility } = &self.tree[ast_id];
|
||||
self.print_ast_id(ast_id.erase());
|
||||
self.print_visibility(*visibility);
|
||||
w!(self, "trait {} {{ ... }}", name.display(self.db, self.edition));
|
||||
}
|
||||
ModItemId::TraitAlias(it) => {
|
||||
let TraitAlias { name, visibility, ast_id } = &self.tree[it];
|
||||
ModItemId::TraitAlias(ast_id) => {
|
||||
let TraitAlias { name, visibility } = &self.tree[ast_id];
|
||||
self.print_ast_id(ast_id.erase());
|
||||
self.print_visibility(*visibility);
|
||||
wln!(self, "trait {} = ..;", name.display(self.db, self.edition));
|
||||
}
|
||||
ModItemId::Impl(it) => {
|
||||
let Impl { ast_id } = &self.tree[it];
|
||||
ModItemId::Impl(ast_id) => {
|
||||
let Impl {} = &self.tree[ast_id];
|
||||
self.print_ast_id(ast_id.erase());
|
||||
w!(self, "impl {{ ... }}");
|
||||
}
|
||||
ModItemId::TypeAlias(it) => {
|
||||
let TypeAlias { name, visibility, ast_id } = &self.tree[it];
|
||||
ModItemId::TypeAlias(ast_id) => {
|
||||
let TypeAlias { name, visibility } = &self.tree[ast_id];
|
||||
self.print_ast_id(ast_id.erase());
|
||||
self.print_visibility(*visibility);
|
||||
w!(self, "type {}", name.display(self.db, self.edition));
|
||||
w!(self, ";");
|
||||
wln!(self);
|
||||
}
|
||||
ModItemId::Mod(it) => {
|
||||
let Mod { name, visibility, kind, ast_id } = &self.tree[it];
|
||||
ModItemId::Mod(ast_id) => {
|
||||
let Mod { name, visibility, kind } = &self.tree[ast_id];
|
||||
self.print_ast_id(ast_id.erase());
|
||||
self.print_visibility(*visibility);
|
||||
w!(self, "mod {}", name.display(self.db, self.edition));
|
||||
@ -287,8 +287,8 @@ impl Printer<'_> {
|
||||
}
|
||||
}
|
||||
}
|
||||
ModItemId::MacroCall(it) => {
|
||||
let MacroCall { path, ast_id, expand_to, ctxt } = &self.tree[it];
|
||||
ModItemId::MacroCall(ast_id) => {
|
||||
let MacroCall { path, expand_to, ctxt } = &self.tree[ast_id];
|
||||
let _ = writeln!(
|
||||
self,
|
||||
"// AstId: {:#?}, SyntaxContextId: {}, ExpandTo: {:?}",
|
||||
@ -298,13 +298,13 @@ impl Printer<'_> {
|
||||
);
|
||||
wln!(self, "{}!(...);", path.display(self.db, self.edition));
|
||||
}
|
||||
ModItemId::MacroRules(it) => {
|
||||
let MacroRules { name, ast_id } = &self.tree[it];
|
||||
ModItemId::MacroRules(ast_id) => {
|
||||
let MacroRules { name } = &self.tree[ast_id];
|
||||
self.print_ast_id(ast_id.erase());
|
||||
wln!(self, "macro_rules! {} {{ ... }}", name.display(self.db, self.edition));
|
||||
}
|
||||
ModItemId::Macro2(it) => {
|
||||
let Macro2 { name, visibility, ast_id } = &self.tree[it];
|
||||
ModItemId::Macro2(ast_id) => {
|
||||
let Macro2 { name, visibility } = &self.tree[ast_id];
|
||||
self.print_ast_id(ast_id.erase());
|
||||
self.print_visibility(*visibility);
|
||||
wln!(self, "macro {} {{ ... }}", name.display(self.db, self.edition));
|
||||
|
@ -1434,11 +1434,10 @@ impl DefCollector<'_> {
|
||||
// normal (as that would just be an identity expansion with extra output)
|
||||
// Instead we treat derive attributes special and apply them separately.
|
||||
|
||||
let item_tree = tree.item_tree(self.db);
|
||||
let ast_adt_id: FileAstId<ast::Adt> = match *mod_item {
|
||||
ModItemId::Struct(strukt) => item_tree[strukt].ast_id.upcast(),
|
||||
ModItemId::Union(union) => item_tree[union].ast_id.upcast(),
|
||||
ModItemId::Enum(enum_) => item_tree[enum_].ast_id.upcast(),
|
||||
ModItemId::Struct(ast_id) => ast_id.upcast(),
|
||||
ModItemId::Union(ast_id) => ast_id.upcast(),
|
||||
ModItemId::Enum(ast_id) => ast_id.upcast(),
|
||||
_ => {
|
||||
let diag = DefDiagnostic::invalid_derive_target(
|
||||
directive.module_id,
|
||||
@ -1750,11 +1749,9 @@ impl ModCollector<'_, '_> {
|
||||
match item {
|
||||
ModItemId::Mod(m) => self.collect_module(m, &attrs),
|
||||
ModItemId::Use(item_tree_id) => {
|
||||
let id = UseLoc {
|
||||
container: module,
|
||||
id: InFile::new(self.file_id(), self.item_tree[item_tree_id].ast_id),
|
||||
}
|
||||
.intern(db);
|
||||
let id =
|
||||
UseLoc { container: module, id: InFile::new(self.file_id(), item_tree_id) }
|
||||
.intern(db);
|
||||
let is_prelude = attrs.by_key(sym::prelude_import).exists();
|
||||
Import::from_use(
|
||||
self.item_tree,
|
||||
@ -1772,12 +1769,12 @@ impl ModCollector<'_, '_> {
|
||||
)
|
||||
}
|
||||
ModItemId::ExternCrate(item_tree_id) => {
|
||||
let item_tree::ExternCrate { name, visibility, alias, ast_id } =
|
||||
let item_tree::ExternCrate { name, visibility, alias } =
|
||||
&self.item_tree[item_tree_id];
|
||||
|
||||
let id = ExternCrateLoc {
|
||||
container: module,
|
||||
id: InFile::new(self.tree_id.file_id(), *ast_id),
|
||||
id: InFile::new(self.tree_id.file_id(), item_tree_id),
|
||||
}
|
||||
.intern(db);
|
||||
def_map.modules[self.module_id].scope.define_extern_crate_decl(id);
|
||||
@ -1840,7 +1837,7 @@ impl ModCollector<'_, '_> {
|
||||
self.def_collector.def_map.diagnostics.push(
|
||||
DefDiagnostic::unresolved_extern_crate(
|
||||
module_id,
|
||||
InFile::new(self.file_id(), *ast_id),
|
||||
InFile::new(self.file_id(), item_tree_id),
|
||||
),
|
||||
);
|
||||
}
|
||||
@ -1848,7 +1845,7 @@ impl ModCollector<'_, '_> {
|
||||
ModItemId::ExternBlock(block) => {
|
||||
let extern_block_id = ExternBlockLoc {
|
||||
container: module,
|
||||
id: InFile::new(self.file_id(), self.item_tree[block].ast_id),
|
||||
id: InFile::new(self.file_id(), block),
|
||||
}
|
||||
.intern(db);
|
||||
self.def_collector.def_map.modules[self.module_id]
|
||||
@ -1859,26 +1856,20 @@ impl ModCollector<'_, '_> {
|
||||
ItemContainerId::ExternBlockId(extern_block_id),
|
||||
)
|
||||
}
|
||||
ModItemId::MacroCall(mac) => {
|
||||
self.collect_macro_call(&self.item_tree[mac], container)
|
||||
}
|
||||
ModItemId::MacroCall(mac) => self.collect_macro_call(mac, container),
|
||||
ModItemId::MacroRules(id) => self.collect_macro_rules(id, module),
|
||||
ModItemId::Macro2(id) => self.collect_macro_def(id, module),
|
||||
ModItemId::Impl(imp) => {
|
||||
let impl_id = ImplLoc {
|
||||
container: module,
|
||||
id: InFile::new(self.file_id(), self.item_tree[imp].ast_id),
|
||||
}
|
||||
.intern(db);
|
||||
let impl_id =
|
||||
ImplLoc { container: module, id: InFile::new(self.file_id(), imp) }
|
||||
.intern(db);
|
||||
self.def_collector.def_map.modules[self.module_id].scope.define_impl(impl_id)
|
||||
}
|
||||
ModItemId::Function(id) => {
|
||||
let it = &self.item_tree[id];
|
||||
let fn_id = FunctionLoc {
|
||||
container,
|
||||
id: InFile::new(self.tree_id.file_id(), it.ast_id),
|
||||
}
|
||||
.intern(db);
|
||||
let fn_id =
|
||||
FunctionLoc { container, id: InFile::new(self.tree_id.file_id(), id) }
|
||||
.intern(db);
|
||||
|
||||
let vis = resolve_vis(def_map, local_def_map, &self.item_tree[it.visibility]);
|
||||
|
||||
@ -1889,7 +1880,7 @@ impl ModCollector<'_, '_> {
|
||||
if let Some(proc_macro) = attrs.parse_proc_macro_decl(&it.name) {
|
||||
self.def_collector.export_proc_macro(
|
||||
proc_macro,
|
||||
InFile::new(self.file_id(), self.item_tree[id].ast_id),
|
||||
InFile::new(self.file_id(), id),
|
||||
fn_id,
|
||||
);
|
||||
}
|
||||
@ -1903,7 +1894,7 @@ impl ModCollector<'_, '_> {
|
||||
let vis = resolve_vis(def_map, local_def_map, &self.item_tree[it.visibility]);
|
||||
update_def(
|
||||
self.def_collector,
|
||||
StructLoc { container: module, id: InFile::new(self.file_id(), it.ast_id) }
|
||||
StructLoc { container: module, id: InFile::new(self.file_id(), id) }
|
||||
.intern(db)
|
||||
.into(),
|
||||
&it.name,
|
||||
@ -1917,7 +1908,7 @@ impl ModCollector<'_, '_> {
|
||||
let vis = resolve_vis(def_map, local_def_map, &self.item_tree[it.visibility]);
|
||||
update_def(
|
||||
self.def_collector,
|
||||
UnionLoc { container: module, id: InFile::new(self.file_id(), it.ast_id) }
|
||||
UnionLoc { container: module, id: InFile::new(self.file_id(), id) }
|
||||
.intern(db)
|
||||
.into(),
|
||||
&it.name,
|
||||
@ -1927,11 +1918,9 @@ impl ModCollector<'_, '_> {
|
||||
}
|
||||
ModItemId::Enum(id) => {
|
||||
let it = &self.item_tree[id];
|
||||
let enum_ = EnumLoc {
|
||||
container: module,
|
||||
id: InFile::new(self.tree_id.file_id(), it.ast_id),
|
||||
}
|
||||
.intern(db);
|
||||
let enum_ =
|
||||
EnumLoc { container: module, id: InFile::new(self.tree_id.file_id(), id) }
|
||||
.intern(db);
|
||||
|
||||
let vis = resolve_vis(def_map, local_def_map, &self.item_tree[it.visibility]);
|
||||
update_def(self.def_collector, enum_.into(), &it.name, vis, false);
|
||||
@ -1939,7 +1928,7 @@ impl ModCollector<'_, '_> {
|
||||
ModItemId::Const(id) => {
|
||||
let it = &self.item_tree[id];
|
||||
let const_id =
|
||||
ConstLoc { container, id: InFile::new(self.tree_id.file_id(), it.ast_id) }
|
||||
ConstLoc { container, id: InFile::new(self.tree_id.file_id(), id) }
|
||||
.intern(db);
|
||||
|
||||
match &it.name {
|
||||
@ -1962,7 +1951,7 @@ impl ModCollector<'_, '_> {
|
||||
let vis = resolve_vis(def_map, local_def_map, &self.item_tree[it.visibility]);
|
||||
update_def(
|
||||
self.def_collector,
|
||||
StaticLoc { container, id: InFile::new(self.file_id(), it.ast_id) }
|
||||
StaticLoc { container, id: InFile::new(self.file_id(), id) }
|
||||
.intern(db)
|
||||
.into(),
|
||||
&it.name,
|
||||
@ -1976,7 +1965,7 @@ impl ModCollector<'_, '_> {
|
||||
let vis = resolve_vis(def_map, local_def_map, &self.item_tree[it.visibility]);
|
||||
update_def(
|
||||
self.def_collector,
|
||||
TraitLoc { container: module, id: InFile::new(self.file_id(), it.ast_id) }
|
||||
TraitLoc { container: module, id: InFile::new(self.file_id(), id) }
|
||||
.intern(db)
|
||||
.into(),
|
||||
&it.name,
|
||||
@ -1990,12 +1979,9 @@ impl ModCollector<'_, '_> {
|
||||
let vis = resolve_vis(def_map, local_def_map, &self.item_tree[it.visibility]);
|
||||
update_def(
|
||||
self.def_collector,
|
||||
TraitAliasLoc {
|
||||
container: module,
|
||||
id: InFile::new(self.file_id(), it.ast_id),
|
||||
}
|
||||
.intern(db)
|
||||
.into(),
|
||||
TraitAliasLoc { container: module, id: InFile::new(self.file_id(), id) }
|
||||
.intern(db)
|
||||
.into(),
|
||||
&it.name,
|
||||
vis,
|
||||
false,
|
||||
@ -2007,7 +1993,7 @@ impl ModCollector<'_, '_> {
|
||||
let vis = resolve_vis(def_map, local_def_map, &self.item_tree[it.visibility]);
|
||||
update_def(
|
||||
self.def_collector,
|
||||
TypeAliasLoc { container, id: InFile::new(self.file_id(), it.ast_id) }
|
||||
TypeAliasLoc { container, id: InFile::new(self.file_id(), id) }
|
||||
.intern(db)
|
||||
.into(),
|
||||
&it.name,
|
||||
@ -2070,16 +2056,16 @@ impl ModCollector<'_, '_> {
|
||||
);
|
||||
}
|
||||
|
||||
fn collect_module(&mut self, module_id: ItemTreeAstId<Mod>, attrs: &Attrs) {
|
||||
fn collect_module(&mut self, module_ast_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];
|
||||
let module = &self.item_tree[module_ast_id];
|
||||
match &module.kind {
|
||||
// inline module, just recurse
|
||||
ModKind::Inline { items } => {
|
||||
let module_id = self.push_child_module(
|
||||
module.name.clone(),
|
||||
module.ast_id,
|
||||
module_ast_id,
|
||||
None,
|
||||
&self.item_tree[module.visibility],
|
||||
);
|
||||
@ -2104,7 +2090,7 @@ impl ModCollector<'_, '_> {
|
||||
}
|
||||
// out of line module, resolve, parse and recurse
|
||||
ModKind::Outline => {
|
||||
let ast_id = AstId::new(self.file_id(), module.ast_id);
|
||||
let ast_id = AstId::new(self.file_id(), module_ast_id);
|
||||
let db = self.def_collector.db;
|
||||
match self.mod_dir.resolve_declaration(
|
||||
db,
|
||||
@ -2123,10 +2109,7 @@ impl ModCollector<'_, '_> {
|
||||
match is_enabled {
|
||||
Err(cfg) => {
|
||||
self.emit_unconfigured_diagnostic(
|
||||
InFile::new(
|
||||
self.file_id(),
|
||||
self.item_tree[module_id].ast_id.erase(),
|
||||
),
|
||||
InFile::new(self.file_id(), module_ast_id.erase()),
|
||||
&cfg,
|
||||
);
|
||||
}
|
||||
@ -2295,11 +2278,11 @@ impl ModCollector<'_, '_> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn collect_macro_rules(&mut self, id: ItemTreeAstId<MacroRules>, module: ModuleId) {
|
||||
fn collect_macro_rules(&mut self, ast_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, id.upcast());
|
||||
let ast_id = InFile::new(self.file_id(), mac.ast_id.upcast());
|
||||
let mac = &self.item_tree[ast_id];
|
||||
let attrs = self.item_tree.attrs(self.def_collector.db, krate, ast_id.upcast());
|
||||
let f_ast_id = InFile::new(self.file_id(), ast_id.upcast());
|
||||
|
||||
let export_attr = || attrs.by_key(sym::macro_export);
|
||||
|
||||
@ -2346,7 +2329,7 @@ impl ModCollector<'_, '_> {
|
||||
self.def_collector
|
||||
.def_map
|
||||
.diagnostics
|
||||
.push(DefDiagnostic::unimplemented_builtin_macro(self.module_id, ast_id));
|
||||
.push(DefDiagnostic::unimplemented_builtin_macro(self.module_id, f_ast_id));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -2362,16 +2345,13 @@ impl ModCollector<'_, '_> {
|
||||
|
||||
let macro_id = MacroRulesLoc {
|
||||
container: module,
|
||||
id: InFile::new(self.file_id(), mac.ast_id),
|
||||
id: InFile::new(self.file_id(), ast_id),
|
||||
flags,
|
||||
expander,
|
||||
edition: self.def_collector.def_map.data.edition,
|
||||
}
|
||||
.intern(self.def_collector.db);
|
||||
self.def_collector.def_map.macro_def_to_macro_id.insert(
|
||||
InFile::new(self.file_id(), self.item_tree[id].ast_id).erase(),
|
||||
macro_id.into(),
|
||||
);
|
||||
self.def_collector.def_map.macro_def_to_macro_id.insert(f_ast_id.erase(), macro_id.into());
|
||||
self.def_collector.define_macro_rules(
|
||||
self.module_id,
|
||||
mac.name.clone(),
|
||||
@ -2380,14 +2360,14 @@ impl ModCollector<'_, '_> {
|
||||
);
|
||||
}
|
||||
|
||||
fn collect_macro_def(&mut self, id: ItemTreeAstId<Macro2>, module: ModuleId) {
|
||||
fn collect_macro_def(&mut self, ast_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());
|
||||
let mac = &self.item_tree[ast_id];
|
||||
let attrs = self.item_tree.attrs(self.def_collector.db, krate, ast_id.upcast());
|
||||
let f_ast_id = InFile::new(self.file_id(), ast_id.upcast());
|
||||
|
||||
// Case 1: builtin macros
|
||||
let mut helpers_opt = None;
|
||||
let attrs = self.item_tree.attrs(self.def_collector.db, krate, id.upcast());
|
||||
let expander = if attrs.by_key(sym::rustc_builtin_macro).exists() {
|
||||
if let Some(expander) = find_builtin_macro(&mac.name) {
|
||||
match expander {
|
||||
@ -2419,7 +2399,7 @@ impl ModCollector<'_, '_> {
|
||||
self.def_collector
|
||||
.def_map
|
||||
.diagnostics
|
||||
.push(DefDiagnostic::unimplemented_builtin_macro(self.module_id, ast_id));
|
||||
.push(DefDiagnostic::unimplemented_builtin_macro(self.module_id, f_ast_id));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
@ -2430,16 +2410,13 @@ impl ModCollector<'_, '_> {
|
||||
|
||||
let macro_id = Macro2Loc {
|
||||
container: module,
|
||||
id: InFile::new(self.file_id(), mac.ast_id),
|
||||
id: InFile::new(self.file_id(), ast_id),
|
||||
expander,
|
||||
allow_internal_unsafe,
|
||||
edition: self.def_collector.def_map.data.edition,
|
||||
}
|
||||
.intern(self.def_collector.db);
|
||||
self.def_collector.def_map.macro_def_to_macro_id.insert(
|
||||
InFile::new(self.file_id(), self.item_tree[id].ast_id).erase(),
|
||||
macro_id.into(),
|
||||
);
|
||||
self.def_collector.def_map.macro_def_to_macro_id.insert(f_ast_id.erase(), macro_id.into());
|
||||
self.def_collector.define_macro_def(
|
||||
self.module_id,
|
||||
mac.name.clone(),
|
||||
@ -2458,9 +2435,10 @@ impl ModCollector<'_, '_> {
|
||||
|
||||
fn collect_macro_call(
|
||||
&mut self,
|
||||
&MacroCall { ref path, ast_id, expand_to, ctxt }: &MacroCall,
|
||||
ast_id: FileAstId<ast::MacroCall>,
|
||||
container: ItemContainerId,
|
||||
) {
|
||||
let &MacroCall { ref path, expand_to, ctxt } = &self.item_tree[ast_id];
|
||||
let ast_id = AstIdWithPath::new(self.file_id(), ast_id, path.clone());
|
||||
let db = self.def_collector.db;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user