diff options
author | Aleksey Kladov <[email protected]> | 2019-10-10 15:48:30 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-10-10 15:48:30 +0100 |
commit | 29e83988be5be6d2bc4d869f00f4bf931b1500fa (patch) | |
tree | a7c8c6d2681fd4fdb2d340b9dd233baccecf8b67 /crates | |
parent | 89826a50fc59f271b8b52ae675e145029727aa35 (diff) |
don't special case macro_use
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir/src/attr.rs | 1 | ||||
-rw-r--r-- | crates/ra_hir/src/nameres/collector.rs | 13 | ||||
-rw-r--r-- | crates/ra_hir/src/nameres/raw.rs | 22 |
3 files changed, 13 insertions, 23 deletions
diff --git a/crates/ra_hir/src/attr.rs b/crates/ra_hir/src/attr.rs index a0a74ab8c..bd159a566 100644 --- a/crates/ra_hir/src/attr.rs +++ b/crates/ra_hir/src/attr.rs | |||
@@ -63,6 +63,7 @@ impl Attr { | |||
63 | self.path.as_ident().map_or(false, |s| s.to_string() == name) | 63 | self.path.as_ident().map_or(false, |s| s.to_string() == name) |
64 | } | 64 | } |
65 | 65 | ||
66 | // FIXME: handle cfg_attr :-) | ||
66 | pub(crate) fn as_cfg(&self) -> Option<&Subtree> { | 67 | pub(crate) fn as_cfg(&self) -> Option<&Subtree> { |
67 | if !self.is_simple_atom("cfg") { | 68 | if !self.is_simple_atom("cfg") { |
68 | return None; | 69 | return None; |
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 | |||
562 | 562 | ||
563 | fn collect_module(&mut self, module: &raw::ModuleData, attrs: &[Attr]) { | 563 | fn collect_module(&mut self, module: &raw::ModuleData, attrs: &[Attr]) { |
564 | let path_attr = self.path_attr(attrs); | 564 | let path_attr = self.path_attr(attrs); |
565 | let is_macro_use = self.is_macro_use(attrs); | ||
565 | match module { | 566 | match module { |
566 | // inline module, just recurse | 567 | // inline module, just recurse |
567 | raw::ModuleData::Definition { name, items, ast_id, is_macro_use } => { | 568 | raw::ModuleData::Definition { name, items, ast_id } => { |
568 | let module_id = | 569 | let module_id = |
569 | self.push_child_module(name.clone(), ast_id.with_file_id(self.file_id), None); | 570 | self.push_child_module(name.clone(), ast_id.with_file_id(self.file_id), None); |
570 | 571 | ||
@@ -576,12 +577,12 @@ where | |||
576 | mod_dir: self.mod_dir.descend_into_definition(name, path_attr), | 577 | mod_dir: self.mod_dir.descend_into_definition(name, path_attr), |
577 | } | 578 | } |
578 | .collect(&*items); | 579 | .collect(&*items); |
579 | if *is_macro_use { | 580 | if is_macro_use { |
580 | self.import_all_legacy_macros(module_id); | 581 | self.import_all_legacy_macros(module_id); |
581 | } | 582 | } |
582 | } | 583 | } |
583 | // out of line module, resolve, parse and recurse | 584 | // out of line module, resolve, parse and recurse |
584 | raw::ModuleData::Declaration { name, ast_id, is_macro_use } => { | 585 | raw::ModuleData::Declaration { name, ast_id } => { |
585 | let ast_id = ast_id.with_file_id(self.file_id); | 586 | let ast_id = ast_id.with_file_id(self.file_id); |
586 | match self.mod_dir.resolve_submodule( | 587 | match self.mod_dir.resolve_submodule( |
587 | self.def_collector.db, | 588 | self.def_collector.db, |
@@ -600,7 +601,7 @@ where | |||
600 | mod_dir, | 601 | mod_dir, |
601 | } | 602 | } |
602 | .collect(raw_items.items()); | 603 | .collect(raw_items.items()); |
603 | if *is_macro_use { | 604 | if is_macro_use { |
604 | self.import_all_legacy_macros(module_id); | 605 | self.import_all_legacy_macros(module_id); |
605 | } | 606 | } |
606 | } | 607 | } |
@@ -720,6 +721,10 @@ where | |||
720 | fn path_attr<'a>(&self, attrs: &'a [Attr]) -> Option<&'a SmolStr> { | 721 | fn path_attr<'a>(&self, attrs: &'a [Attr]) -> Option<&'a SmolStr> { |
721 | attrs.iter().find_map(|attr| attr.as_path()) | 722 | attrs.iter().find_map(|attr| attr.as_path()) |
722 | } | 723 | } |
724 | |||
725 | fn is_macro_use<'a>(&self, attrs: &'a [Attr]) -> bool { | ||
726 | attrs.iter().any(|attr| attr.is_simple_atom("macro_use")) | ||
727 | } | ||
723 | } | 728 | } |
724 | 729 | ||
725 | fn is_macro_rules(path: &Path) -> bool { | 730 | 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); | |||
149 | 149 | ||
150 | #[derive(Debug, PartialEq, Eq)] | 150 | #[derive(Debug, PartialEq, Eq)] |
151 | pub(super) enum ModuleData { | 151 | pub(super) enum ModuleData { |
152 | Declaration { | 152 | Declaration { name: Name, ast_id: FileAstId<ast::Module> }, |
153 | name: Name, | 153 | Definition { name: Name, ast_id: FileAstId<ast::Module>, items: Vec<RawItem> }, |
154 | ast_id: FileAstId<ast::Module>, | ||
155 | is_macro_use: bool, | ||
156 | }, | ||
157 | Definition { | ||
158 | name: Name, | ||
159 | ast_id: FileAstId<ast::Module>, | ||
160 | items: Vec<RawItem>, | ||
161 | is_macro_use: bool, | ||
162 | }, | ||
163 | } | 154 | } |
164 | 155 | ||
165 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 156 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
@@ -290,14 +281,8 @@ impl<DB: AstDatabase> RawItemsCollector<&DB> { | |||
290 | let attrs = self.parse_attrs(&module); | 281 | let attrs = self.parse_attrs(&module); |
291 | 282 | ||
292 | let ast_id = self.source_ast_id_map.ast_id(&module); | 283 | let ast_id = self.source_ast_id_map.ast_id(&module); |
293 | // FIXME: cfg_attr | ||
294 | let is_macro_use = module.has_atom_attr("macro_use"); | ||
295 | if module.has_semi() { | 284 | if module.has_semi() { |
296 | let item = self.raw_items.modules.alloc(ModuleData::Declaration { | 285 | let item = self.raw_items.modules.alloc(ModuleData::Declaration { name, ast_id }); |
297 | name, | ||
298 | ast_id, | ||
299 | is_macro_use, | ||
300 | }); | ||
301 | self.push_item(current_module, attrs, RawItemKind::Module(item)); | 286 | self.push_item(current_module, attrs, RawItemKind::Module(item)); |
302 | return; | 287 | return; |
303 | } | 288 | } |
@@ -307,7 +292,6 @@ impl<DB: AstDatabase> RawItemsCollector<&DB> { | |||
307 | name, | 292 | name, |
308 | ast_id, | 293 | ast_id, |
309 | items: Vec::new(), | 294 | items: Vec::new(), |
310 | is_macro_use, | ||
311 | }); | 295 | }); |
312 | self.process_module(Some(item), item_list); | 296 | self.process_module(Some(item), item_list); |
313 | self.push_item(current_module, attrs, RawItemKind::Module(item)); | 297 | self.push_item(current_module, attrs, RawItemKind::Module(item)); |