aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/nameres/collector.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-10-10 15:42:29 +0100
committerAleksey Kladov <[email protected]>2019-10-10 15:42:29 +0100
commit89826a50fc59f271b8b52ae675e145029727aa35 (patch)
treeedbce072fccea11cc7331f5b5dbdca40f6a4bbb4 /crates/ra_hir/src/nameres/collector.rs
parentb36b8970ccefa7c98f827caebf6dda71ff3d99c4 (diff)
don't special case path attr
Diffstat (limited to 'crates/ra_hir/src/nameres/collector.rs')
-rw-r--r--crates/ra_hir/src/nameres/collector.rs21
1 files changed, 14 insertions, 7 deletions
diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs
index 5dacdb0d9..54514becc 100644
--- a/crates/ra_hir/src/nameres/collector.rs
+++ b/crates/ra_hir/src/nameres/collector.rs
@@ -2,7 +2,7 @@
2 2
3use ra_cfg::CfgOptions; 3use ra_cfg::CfgOptions;
4use ra_db::FileId; 4use ra_db::FileId;
5use ra_syntax::ast; 5use ra_syntax::{ast, SmolStr};
6use rustc_hash::FxHashMap; 6use rustc_hash::FxHashMap;
7use test_utils::tested_by; 7use test_utils::tested_by;
8 8
@@ -546,7 +546,9 @@ where
546 for item in items { 546 for item in items {
547 if self.is_cfg_enabled(item.attrs()) { 547 if self.is_cfg_enabled(item.attrs()) {
548 match item.kind { 548 match item.kind {
549 raw::RawItemKind::Module(m) => self.collect_module(&self.raw_items[m]), 549 raw::RawItemKind::Module(m) => {
550 self.collect_module(&self.raw_items[m], item.attrs())
551 }
550 raw::RawItemKind::Import(import_id) => self 552 raw::RawItemKind::Import(import_id) => self
551 .def_collector 553 .def_collector
552 .unresolved_imports 554 .unresolved_imports
@@ -558,10 +560,11 @@ where
558 } 560 }
559 } 561 }
560 562
561 fn collect_module(&mut self, module: &raw::ModuleData) { 563 fn collect_module(&mut self, module: &raw::ModuleData, attrs: &[Attr]) {
564 let path_attr = self.path_attr(attrs);
562 match module { 565 match module {
563 // inline module, just recurse 566 // inline module, just recurse
564 raw::ModuleData::Definition { name, items, ast_id, attr_path, is_macro_use } => { 567 raw::ModuleData::Definition { name, items, ast_id, is_macro_use } => {
565 let module_id = 568 let module_id =
566 self.push_child_module(name.clone(), ast_id.with_file_id(self.file_id), None); 569 self.push_child_module(name.clone(), ast_id.with_file_id(self.file_id), None);
567 570
@@ -570,7 +573,7 @@ where
570 module_id, 573 module_id,
571 file_id: self.file_id, 574 file_id: self.file_id,
572 raw_items: self.raw_items, 575 raw_items: self.raw_items,
573 mod_dir: self.mod_dir.descend_into_definition(name, attr_path.as_ref()), 576 mod_dir: self.mod_dir.descend_into_definition(name, path_attr),
574 } 577 }
575 .collect(&*items); 578 .collect(&*items);
576 if *is_macro_use { 579 if *is_macro_use {
@@ -578,13 +581,13 @@ where
578 } 581 }
579 } 582 }
580 // out of line module, resolve, parse and recurse 583 // out of line module, resolve, parse and recurse
581 raw::ModuleData::Declaration { name, ast_id, attr_path, is_macro_use } => { 584 raw::ModuleData::Declaration { name, ast_id, is_macro_use } => {
582 let ast_id = ast_id.with_file_id(self.file_id); 585 let ast_id = ast_id.with_file_id(self.file_id);
583 match self.mod_dir.resolve_submodule( 586 match self.mod_dir.resolve_submodule(
584 self.def_collector.db, 587 self.def_collector.db,
585 self.file_id, 588 self.file_id,
586 name, 589 name,
587 attr_path.as_ref(), 590 path_attr,
588 ) { 591 ) {
589 Ok((file_id, mod_dir)) => { 592 Ok((file_id, mod_dir)) => {
590 let module_id = self.push_child_module(name.clone(), ast_id, Some(file_id)); 593 let module_id = self.push_child_module(name.clone(), ast_id, Some(file_id));
@@ -713,6 +716,10 @@ where
713 fn is_cfg_enabled(&self, attrs: &[Attr]) -> bool { 716 fn is_cfg_enabled(&self, attrs: &[Attr]) -> bool {
714 attrs.iter().all(|attr| attr.is_cfg_enabled(&self.def_collector.cfg_options) != Some(false)) 717 attrs.iter().all(|attr| attr.is_cfg_enabled(&self.def_collector.cfg_options) != Some(false))
715 } 718 }
719
720 fn path_attr<'a>(&self, attrs: &'a [Attr]) -> Option<&'a SmolStr> {
721 attrs.iter().find_map(|attr| attr.as_path())
722 }
716} 723}
717 724
718fn is_macro_rules(path: &Path) -> bool { 725fn is_macro_rules(path: &Path) -> bool {