From 29e83988be5be6d2bc4d869f00f4bf931b1500fa Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 10 Oct 2019 17:48:30 +0300 Subject: don't special case macro_use --- crates/ra_hir/src/nameres/collector.rs | 13 +++++++++---- crates/ra_hir/src/nameres/raw.rs | 22 +++------------------- 2 files changed, 12 insertions(+), 23 deletions(-) (limited to 'crates/ra_hir/src/nameres') diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs index 54514becc..aa5885f04 100644 --- a/crates/ra_hir/src/nameres/collector.rs +++ b/crates/ra_hir/src/nameres/collector.rs @@ -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 { diff --git a/crates/ra_hir/src/nameres/raw.rs b/crates/ra_hir/src/nameres/raw.rs index 469fd8ea7..57f2929c3 100644 --- a/crates/ra_hir/src/nameres/raw.rs +++ b/crates/ra_hir/src/nameres/raw.rs @@ -149,17 +149,8 @@ impl_arena_id!(Module); #[derive(Debug, PartialEq, Eq)] pub(super) enum ModuleData { - Declaration { - name: Name, - ast_id: FileAstId, - is_macro_use: bool, - }, - Definition { - name: Name, - ast_id: FileAstId, - items: Vec, - is_macro_use: bool, - }, + Declaration { name: Name, ast_id: FileAstId }, + Definition { name: Name, ast_id: FileAstId, items: Vec }, } #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] @@ -290,14 +281,8 @@ impl 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 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)); -- cgit v1.2.3