mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 22:54:58 +00:00
Remove unnecessary macro_declarations from ItemScope
This commit is contained in:
parent
dbada38b61
commit
55ec93a337
6 changed files with 25 additions and 57 deletions
|
@ -1767,11 +1767,13 @@ impl Macro {
|
|||
}
|
||||
|
||||
pub fn name(self, _db: &dyn HirDatabase) -> Option<Name> {
|
||||
match self.id {
|
||||
MacroId::Macro2Id(_id) => todo!(),
|
||||
MacroId::MacroRulesId(_id) => todo!(),
|
||||
MacroId::ProcMacroId(_id) => todo!(),
|
||||
}
|
||||
// match self.id {
|
||||
// MacroId::Macro2Id(id) => db.macro2_data(id).name.clone(),
|
||||
// MacroId::MacroRulesId(id) => db.macro_rules_data(id).name.clone(),
|
||||
// MacroId::ProcMacroId(id) => db.proc_macro_data(id).name.clone(),
|
||||
// }
|
||||
// FIXME
|
||||
None
|
||||
}
|
||||
|
||||
pub fn kind(&self, db: &dyn HirDatabase) -> MacroKind {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
//! File symbol extraction.
|
||||
|
||||
use base_db::FileRange;
|
||||
use either::Either;
|
||||
use hir_def::{
|
||||
item_tree::ItemTreeNode, src::HasSource, AdtId, AssocItemId, AssocItemLoc, DefWithBodyId,
|
||||
ImplId, ItemContainerId, Lookup, MacroId, ModuleDefId, ModuleId, TraitId,
|
||||
|
@ -10,7 +9,7 @@ use hir_expand::{HirFileId, InFile};
|
|||
use hir_ty::db::HirDatabase;
|
||||
use syntax::{ast::HasName, AstNode, SmolStr, SyntaxNode, SyntaxNodePtr};
|
||||
|
||||
use crate::{HasSource as _, Macro, Module, Semantics};
|
||||
use crate::{Module, Semantics};
|
||||
|
||||
/// The actual data that is stored in the index. It should be as compact as
|
||||
/// possible.
|
||||
|
@ -175,10 +174,6 @@ impl<'a> SymbolCollector<'a> {
|
|||
for const_id in scope.unnamed_consts() {
|
||||
self.collect_from_body(const_id);
|
||||
}
|
||||
|
||||
for macro_def_id in scope.macro_declarations() {
|
||||
self.push_decl_macro(macro_def_id.into());
|
||||
}
|
||||
}
|
||||
|
||||
fn collect_from_body(&mut self, body_id: impl Into<DefWithBodyId>) {
|
||||
|
@ -333,29 +328,6 @@ impl<'a> SymbolCollector<'a> {
|
|||
})
|
||||
}
|
||||
|
||||
fn push_decl_macro(&mut self, macro_def: Macro) {
|
||||
self.push_file_symbol(|s| {
|
||||
let name = macro_def.name(s.db)?.as_text()?;
|
||||
let source = macro_def.source(s.db)?;
|
||||
|
||||
let (ptr, name_ptr) = match source.value {
|
||||
Either::Left(m) => {
|
||||
(SyntaxNodePtr::new(m.syntax()), SyntaxNodePtr::new(m.name()?.syntax()))
|
||||
}
|
||||
Either::Right(f) => {
|
||||
(SyntaxNodePtr::new(f.syntax()), SyntaxNodePtr::new(f.name()?.syntax()))
|
||||
}
|
||||
};
|
||||
|
||||
Some(FileSymbol {
|
||||
name,
|
||||
kind: FileSymbolKind::Macro,
|
||||
container_name: s.current_container_name(),
|
||||
loc: DeclarationLocation { hir_file_id: source.file_id, name_ptr, ptr },
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
fn push_file_symbol(&mut self, f: impl FnOnce(&Self) -> Option<FileSymbol>) {
|
||||
if let Some(file_symbol) = f(self) {
|
||||
self.symbols.push(file_symbol);
|
||||
|
|
|
@ -93,6 +93,7 @@ pub trait DefDatabase: InternDatabase + AstDatabase + Upcast<dyn AstDatabase> {
|
|||
|
||||
#[salsa::invoke(StructData::struct_data_query)]
|
||||
fn struct_data(&self, id: StructId) -> Arc<StructData>;
|
||||
|
||||
#[salsa::invoke(StructData::union_data_query)]
|
||||
fn union_data(&self, id: UnionId) -> Arc<StructData>;
|
||||
|
||||
|
|
|
@ -45,7 +45,6 @@ pub struct ItemScope {
|
|||
/// The defs declared in this scope. Each def has a single scope where it is
|
||||
/// declared.
|
||||
declarations: Vec<ModuleDefId>,
|
||||
macro_declarations: Vec<MacroId>,
|
||||
|
||||
impls: Vec<ImplId>,
|
||||
unnamed_consts: Vec<ConstId>,
|
||||
|
@ -109,10 +108,6 @@ impl ItemScope {
|
|||
self.declarations.iter().copied()
|
||||
}
|
||||
|
||||
pub fn macro_declarations(&self) -> impl Iterator<Item = MacroId> + '_ {
|
||||
self.macro_declarations.iter().copied()
|
||||
}
|
||||
|
||||
pub fn impls(&self) -> impl Iterator<Item = ImplId> + ExactSizeIterator + '_ {
|
||||
self.impls.iter().copied()
|
||||
}
|
||||
|
@ -177,10 +172,6 @@ impl ItemScope {
|
|||
self.declarations.push(def)
|
||||
}
|
||||
|
||||
pub(crate) fn declare_macro(&mut self, def: MacroId) {
|
||||
self.macro_declarations.push(def);
|
||||
}
|
||||
|
||||
pub(crate) fn get_legacy_macro(&self, name: &Name) -> Option<MacroRulesId> {
|
||||
self.legacy_macros.get(name).copied()
|
||||
}
|
||||
|
@ -380,7 +371,6 @@ impl ItemScope {
|
|||
macros,
|
||||
unresolved,
|
||||
declarations,
|
||||
macro_declarations,
|
||||
impls,
|
||||
unnamed_consts,
|
||||
unnamed_trait_imports,
|
||||
|
@ -393,7 +383,6 @@ impl ItemScope {
|
|||
macros.shrink_to_fit();
|
||||
unresolved.shrink_to_fit();
|
||||
declarations.shrink_to_fit();
|
||||
macro_declarations.shrink_to_fit();
|
||||
impls.shrink_to_fit();
|
||||
unnamed_consts.shrink_to_fit();
|
||||
unnamed_trait_imports.shrink_to_fit();
|
||||
|
|
|
@ -448,7 +448,7 @@ pub enum ModuleDefId {
|
|||
MacroId(MacroId),
|
||||
}
|
||||
impl_from!(
|
||||
MacroId,
|
||||
MacroId(Macro2Id, MacroRulesId, ProcMacroId),
|
||||
ModuleId,
|
||||
FunctionId,
|
||||
AdtId(StructId, EnumId, UnionId),
|
||||
|
|
|
@ -606,16 +606,16 @@ impl DefCollector<'_> {
|
|||
) {
|
||||
// Textual scoping
|
||||
self.define_legacy_macro(module_id, name.clone(), macro_);
|
||||
let macro_ = macro_.into();
|
||||
self.def_map.modules[module_id].scope.declare_macro(macro_);
|
||||
|
||||
// Module scoping
|
||||
// In Rust, `#[macro_export]` macros are unconditionally visible at the
|
||||
// crate root, even if the parent modules is **not** visible.
|
||||
if export {
|
||||
let module_id = self.def_map.root;
|
||||
self.def_map.modules[module_id].scope.declare(macro_.into());
|
||||
self.update(
|
||||
self.def_map.root,
|
||||
&[(Some(name), PerNs::macros(macro_, Visibility::Public))],
|
||||
module_id,
|
||||
&[(Some(name), PerNs::macros(macro_.into(), Visibility::Public))],
|
||||
Visibility::Public,
|
||||
ImportType::Named,
|
||||
);
|
||||
|
@ -646,9 +646,13 @@ impl DefCollector<'_> {
|
|||
) {
|
||||
let vis =
|
||||
self.def_map.resolve_visibility(self.db, module_id, vis).unwrap_or(Visibility::Public);
|
||||
let macro_ = macro_.into();
|
||||
self.def_map.modules[module_id].scope.declare_macro(macro_);
|
||||
self.update(module_id, &[(Some(name), PerNs::macros(macro_, vis))], vis, ImportType::Named);
|
||||
self.def_map.modules[module_id].scope.declare(macro_.into());
|
||||
self.update(
|
||||
module_id,
|
||||
&[(Some(name), PerNs::macros(macro_.into(), Visibility::Public))],
|
||||
vis,
|
||||
ImportType::Named,
|
||||
);
|
||||
}
|
||||
|
||||
/// Define a proc macro
|
||||
|
@ -656,11 +660,11 @@ impl DefCollector<'_> {
|
|||
/// A proc macro is similar to normal macro scope, but it would not visible in legacy textual scoped.
|
||||
/// And unconditionally exported.
|
||||
fn define_proc_macro(&mut self, name: Name, macro_: ProcMacroId) {
|
||||
let macro_ = macro_.into();
|
||||
self.def_map.modules[self.def_map.root].scope.declare_macro(macro_);
|
||||
let module_id = self.def_map.root;
|
||||
self.def_map.modules[module_id].scope.declare(macro_.into());
|
||||
self.update(
|
||||
self.def_map.root,
|
||||
&[(Some(name), PerNs::macros(macro_, Visibility::Public))],
|
||||
module_id,
|
||||
&[(Some(name), PerNs::macros(macro_.into(), Visibility::Public))],
|
||||
Visibility::Public,
|
||||
ImportType::Named,
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue