mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-15 01:17:27 +00:00
don't special case macro_use
This commit is contained in:
parent
89826a50fc
commit
29e83988be
3 changed files with 13 additions and 23 deletions
|
@ -63,6 +63,7 @@ impl Attr {
|
|||
self.path.as_ident().map_or(false, |s| s.to_string() == name)
|
||||
}
|
||||
|
||||
// FIXME: handle cfg_attr :-)
|
||||
pub(crate) fn as_cfg(&self) -> Option<&Subtree> {
|
||||
if !self.is_simple_atom("cfg") {
|
||||
return None;
|
||||
|
|
|
@ -562,9 +562,10 @@ where
|
|||
|
||||
fn collect_module(&mut self, module: &raw::ModuleData, attrs: &[Attr]) {
|
||||
let path_attr = self.path_attr(attrs);
|
||||
let is_macro_use = self.is_macro_use(attrs);
|
||||
match module {
|
||||
// inline module, just recurse
|
||||
raw::ModuleData::Definition { name, items, ast_id, is_macro_use } => {
|
||||
raw::ModuleData::Definition { name, items, ast_id } => {
|
||||
let module_id =
|
||||
self.push_child_module(name.clone(), ast_id.with_file_id(self.file_id), None);
|
||||
|
||||
|
@ -576,12 +577,12 @@ where
|
|||
mod_dir: self.mod_dir.descend_into_definition(name, path_attr),
|
||||
}
|
||||
.collect(&*items);
|
||||
if *is_macro_use {
|
||||
if is_macro_use {
|
||||
self.import_all_legacy_macros(module_id);
|
||||
}
|
||||
}
|
||||
// out of line module, resolve, parse and recurse
|
||||
raw::ModuleData::Declaration { name, ast_id, is_macro_use } => {
|
||||
raw::ModuleData::Declaration { name, ast_id } => {
|
||||
let ast_id = ast_id.with_file_id(self.file_id);
|
||||
match self.mod_dir.resolve_submodule(
|
||||
self.def_collector.db,
|
||||
|
@ -600,7 +601,7 @@ where
|
|||
mod_dir,
|
||||
}
|
||||
.collect(raw_items.items());
|
||||
if *is_macro_use {
|
||||
if is_macro_use {
|
||||
self.import_all_legacy_macros(module_id);
|
||||
}
|
||||
}
|
||||
|
@ -720,6 +721,10 @@ where
|
|||
fn path_attr<'a>(&self, attrs: &'a [Attr]) -> Option<&'a SmolStr> {
|
||||
attrs.iter().find_map(|attr| attr.as_path())
|
||||
}
|
||||
|
||||
fn is_macro_use<'a>(&self, attrs: &'a [Attr]) -> bool {
|
||||
attrs.iter().any(|attr| attr.is_simple_atom("macro_use"))
|
||||
}
|
||||
}
|
||||
|
||||
fn is_macro_rules(path: &Path) -> bool {
|
||||
|
|
|
@ -149,17 +149,8 @@ impl_arena_id!(Module);
|
|||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub(super) enum ModuleData {
|
||||
Declaration {
|
||||
name: Name,
|
||||
ast_id: FileAstId<ast::Module>,
|
||||
is_macro_use: bool,
|
||||
},
|
||||
Definition {
|
||||
name: Name,
|
||||
ast_id: FileAstId<ast::Module>,
|
||||
items: Vec<RawItem>,
|
||||
is_macro_use: bool,
|
||||
},
|
||||
Declaration { name: Name, ast_id: FileAstId<ast::Module> },
|
||||
Definition { name: Name, ast_id: FileAstId<ast::Module>, items: Vec<RawItem> },
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
|
@ -290,14 +281,8 @@ impl<DB: AstDatabase> RawItemsCollector<&DB> {
|
|||
let attrs = self.parse_attrs(&module);
|
||||
|
||||
let ast_id = self.source_ast_id_map.ast_id(&module);
|
||||
// FIXME: cfg_attr
|
||||
let is_macro_use = module.has_atom_attr("macro_use");
|
||||
if module.has_semi() {
|
||||
let item = self.raw_items.modules.alloc(ModuleData::Declaration {
|
||||
name,
|
||||
ast_id,
|
||||
is_macro_use,
|
||||
});
|
||||
let item = self.raw_items.modules.alloc(ModuleData::Declaration { name, ast_id });
|
||||
self.push_item(current_module, attrs, RawItemKind::Module(item));
|
||||
return;
|
||||
}
|
||||
|
@ -307,7 +292,6 @@ impl<DB: AstDatabase> RawItemsCollector<&DB> {
|
|||
name,
|
||||
ast_id,
|
||||
items: Vec::new(),
|
||||
is_macro_use,
|
||||
});
|
||||
self.process_module(Some(item), item_list);
|
||||
self.push_item(current_module, attrs, RawItemKind::Module(item));
|
||||
|
|
Loading…
Reference in a new issue