aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-10-10 15:34:05 +0100
committerGitHub <[email protected]>2019-10-10 15:34:05 +0100
commit19cc85bf0af04167cd75dcb5fdc40bcdfe51f3e0 (patch)
tree356a3b29a03f6343b8aa14d548ba40efaabbd963 /crates/ra_hir/src
parent62acb9f233ec7aef5463146fd14c02d46cf8e9c1 (diff)
parentb36b8970ccefa7c98f827caebf6dda71ff3d99c4 (diff)
Merge #1985
1985: simplify a bit r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/nameres/collector.rs13
-rw-r--r--crates/ra_hir/src/nameres/raw.rs10
2 files changed, 13 insertions, 10 deletions
diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs
index 88aee7437..5dacdb0d9 100644
--- a/crates/ra_hir/src/nameres/collector.rs
+++ b/crates/ra_hir/src/nameres/collector.rs
@@ -7,6 +7,7 @@ use rustc_hash::FxHashMap;
7use test_utils::tested_by; 7use test_utils::tested_by;
8 8
9use crate::{ 9use crate::{
10 attr::Attr,
10 db::DefDatabase, 11 db::DefDatabase,
11 ids::{AstItemDef, LocationCtx, MacroCallId, MacroCallLoc, MacroDefId, MacroFileKind}, 12 ids::{AstItemDef, LocationCtx, MacroCallId, MacroCallLoc, MacroDefId, MacroFileKind},
12 name::MACRO_RULES, 13 name::MACRO_RULES,
@@ -532,7 +533,7 @@ where
532 // `#[macro_use] extern crate` is hoisted to imports macros before collecting 533 // `#[macro_use] extern crate` is hoisted to imports macros before collecting
533 // any other items. 534 // any other items.
534 for item in items { 535 for item in items {
535 if self.is_cfg_enabled(&item.attrs) { 536 if self.is_cfg_enabled(item.attrs()) {
536 if let raw::RawItemKind::Import(import_id) = item.kind { 537 if let raw::RawItemKind::Import(import_id) = item.kind {
537 let import = self.raw_items[import_id].clone(); 538 let import = self.raw_items[import_id].clone();
538 if import.is_extern_crate && import.is_macro_use { 539 if import.is_extern_crate && import.is_macro_use {
@@ -543,7 +544,7 @@ where
543 } 544 }
544 545
545 for item in items { 546 for item in items {
546 if self.is_cfg_enabled(&item.attrs) { 547 if self.is_cfg_enabled(item.attrs()) {
547 match item.kind { 548 match item.kind {
548 raw::RawItemKind::Module(m) => self.collect_module(&self.raw_items[m]), 549 raw::RawItemKind::Module(m) => self.collect_module(&self.raw_items[m]),
549 raw::RawItemKind::Import(import_id) => self 550 raw::RawItemKind::Import(import_id) => self
@@ -709,12 +710,8 @@ where
709 } 710 }
710 } 711 }
711 712
712 fn is_cfg_enabled(&self, attrs: &raw::Attrs) -> bool { 713 fn is_cfg_enabled(&self, attrs: &[Attr]) -> bool {
713 attrs.as_ref().map_or(true, |attrs| { 714 attrs.iter().all(|attr| attr.is_cfg_enabled(&self.def_collector.cfg_options) != Some(false))
714 attrs
715 .iter()
716 .all(|attr| attr.is_cfg_enabled(&self.def_collector.cfg_options) != Some(false))
717 })
718 } 715 }
719} 716}
720 717
diff --git a/crates/ra_hir/src/nameres/raw.rs b/crates/ra_hir/src/nameres/raw.rs
index 623b343c4..5f93f920f 100644
--- a/crates/ra_hir/src/nameres/raw.rs
+++ b/crates/ra_hir/src/nameres/raw.rs
@@ -121,14 +121,20 @@ impl Index<Macro> for RawItems {
121} 121}
122 122
123// Avoid heap allocation on items without attributes. 123// Avoid heap allocation on items without attributes.
124pub(super) type Attrs = Option<Arc<[Attr]>>; 124type Attrs = Option<Arc<[Attr]>>;
125 125
126#[derive(Debug, PartialEq, Eq, Clone)] 126#[derive(Debug, PartialEq, Eq, Clone)]
127pub(super) struct RawItem { 127pub(super) struct RawItem {
128 pub(super) attrs: Attrs, 128 attrs: Attrs,
129 pub(super) kind: RawItemKind, 129 pub(super) kind: RawItemKind,
130} 130}
131 131
132impl RawItem {
133 pub(super) fn attrs(&self) -> &[Attr] {
134 self.attrs.as_ref().map_or(&[], |it| &*it)
135 }
136}
137
132#[derive(Debug, PartialEq, Eq, Clone, Copy)] 138#[derive(Debug, PartialEq, Eq, Clone, Copy)]
133pub(super) enum RawItemKind { 139pub(super) enum RawItemKind {
134 Module(Module), 140 Module(Module),