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