aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/nameres/collector.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-11-22 08:27:47 +0000
committerAleksey Kladov <[email protected]>2019-11-22 08:27:47 +0000
commite42f9627664cc3c44094e1c4f985270fbfd592b1 (patch)
tree81603da9c34f301cf82e1ceae80313b8eb9e10c4 /crates/ra_hir_def/src/nameres/collector.rs
parenta1346bba5c457d1aa0a35f44231bed8b494b7d60 (diff)
Encapsulate Attrs
Diffstat (limited to 'crates/ra_hir_def/src/nameres/collector.rs')
-rw-r--r--crates/ra_hir_def/src/nameres/collector.rs20
1 files changed, 8 insertions, 12 deletions
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs
index aae3dcadf..7902293e8 100644
--- a/crates/ra_hir_def/src/nameres/collector.rs
+++ b/crates/ra_hir_def/src/nameres/collector.rs
@@ -12,7 +12,7 @@ use rustc_hash::FxHashMap;
12use test_utils::tested_by; 12use test_utils::tested_by;
13 13
14use crate::{ 14use crate::{
15 attr::Attr, 15 attr::Attrs,
16 db::DefDatabase2, 16 db::DefDatabase2,
17 nameres::{ 17 nameres::{
18 diagnostics::DefDiagnostic, mod_resolution::ModDir, path_resolution::ReachedFixedPoint, 18 diagnostics::DefDiagnostic, mod_resolution::ModDir, path_resolution::ReachedFixedPoint,
@@ -549,7 +549,7 @@ where
549 // `#[macro_use] extern crate` is hoisted to imports macros before collecting 549 // `#[macro_use] extern crate` is hoisted to imports macros before collecting
550 // any other items. 550 // any other items.
551 for item in items { 551 for item in items {
552 if self.is_cfg_enabled(item.attrs()) { 552 if self.is_cfg_enabled(&item.attrs) {
553 if let raw::RawItemKind::Import(import_id) = item.kind { 553 if let raw::RawItemKind::Import(import_id) = item.kind {
554 let import = self.raw_items[import_id].clone(); 554 let import = self.raw_items[import_id].clone();
555 if import.is_extern_crate && import.is_macro_use { 555 if import.is_extern_crate && import.is_macro_use {
@@ -560,10 +560,10 @@ where
560 } 560 }
561 561
562 for item in items { 562 for item in items {
563 if self.is_cfg_enabled(item.attrs()) { 563 if self.is_cfg_enabled(&item.attrs) {
564 match item.kind { 564 match item.kind {
565 raw::RawItemKind::Module(m) => { 565 raw::RawItemKind::Module(m) => {
566 self.collect_module(&self.raw_items[m], item.attrs()) 566 self.collect_module(&self.raw_items[m], &item.attrs)
567 } 567 }
568 raw::RawItemKind::Import(import_id) => self 568 raw::RawItemKind::Import(import_id) => self
569 .def_collector 569 .def_collector
@@ -585,9 +585,9 @@ where
585 } 585 }
586 } 586 }
587 587
588 fn collect_module(&mut self, module: &raw::ModuleData, attrs: &[Attr]) { 588 fn collect_module(&mut self, module: &raw::ModuleData, attrs: &Attrs) {
589 let path_attr = self.path_attr(attrs); 589 let path_attr = self.path_attr(attrs);
590 let is_macro_use = self.is_macro_use(attrs); 590 let is_macro_use = attrs.has_atom("macro_use");
591 match module { 591 match module {
592 // inline module, just recurse 592 // inline module, just recurse
593 raw::ModuleData::Definition { name, items, ast_id } => { 593 raw::ModuleData::Definition { name, items, ast_id } => {
@@ -779,17 +779,13 @@ where
779 } 779 }
780 } 780 }
781 781
782 fn is_cfg_enabled(&self, attrs: &[Attr]) -> bool { 782 fn is_cfg_enabled(&self, attrs: &Attrs) -> bool {
783 attrs.iter().all(|attr| attr.is_cfg_enabled(&self.def_collector.cfg_options) != Some(false)) 783 attrs.iter().all(|attr| attr.is_cfg_enabled(&self.def_collector.cfg_options) != Some(false))
784 } 784 }
785 785
786 fn path_attr<'a>(&self, attrs: &'a [Attr]) -> Option<&'a SmolStr> { 786 fn path_attr<'a>(&self, attrs: &'a Attrs) -> Option<&'a SmolStr> {
787 attrs.iter().find_map(|attr| attr.as_path()) 787 attrs.iter().find_map(|attr| attr.as_path())
788 } 788 }
789
790 fn is_macro_use<'a>(&self, attrs: &'a [Attr]) -> bool {
791 attrs.iter().any(|attr| attr.is_simple_atom("macro_use"))
792 }
793} 789}
794 790
795fn is_macro_rules(path: &Path) -> bool { 791fn is_macro_rules(path: &Path) -> bool {