diff options
author | Aleksey Kladov <[email protected]> | 2019-11-24 12:28:45 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-11-24 12:28:45 +0000 |
commit | 8e36cb586038e2c12e6eceae57f7a95684fc6c6d (patch) | |
tree | 178c95a19df6a463e0db472b51123355f794ad90 /crates | |
parent | 151180057b0304ee4dee75401e8f1aaa7aaaec21 (diff) |
Simplify
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir_def/src/attr.rs | 12 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/collector.rs | 12 |
2 files changed, 5 insertions, 19 deletions
diff --git a/crates/ra_hir_def/src/attr.rs b/crates/ra_hir_def/src/attr.rs index 87f411599..7d8f0d915 100644 --- a/crates/ra_hir_def/src/attr.rs +++ b/crates/ra_hir_def/src/attr.rs | |||
@@ -144,17 +144,7 @@ impl Attr { | |||
144 | } | 144 | } |
145 | } | 145 | } |
146 | 146 | ||
147 | pub fn as_path(&self) -> Option<&SmolStr> { | 147 | pub(crate) fn is_cfg_enabled(&self, cfg_options: &CfgOptions) -> Option<bool> { |
148 | if !self.is_simple_atom("path") { | ||
149 | return None; | ||
150 | } | ||
151 | match &self.input { | ||
152 | Some(AttrInput::Literal(it)) => Some(it), | ||
153 | _ => None, | ||
154 | } | ||
155 | } | ||
156 | |||
157 | pub fn is_cfg_enabled(&self, cfg_options: &CfgOptions) -> Option<bool> { | ||
158 | cfg_options.is_cfg_enabled(self.as_cfg()?) | 148 | cfg_options.is_cfg_enabled(self.as_cfg()?) |
159 | } | 149 | } |
160 | } | 150 | } |
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index 7b2487999..15941a1cb 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs | |||
@@ -7,7 +7,7 @@ use hir_expand::{ | |||
7 | }; | 7 | }; |
8 | use ra_cfg::CfgOptions; | 8 | use ra_cfg::CfgOptions; |
9 | use ra_db::{CrateId, FileId}; | 9 | use ra_db::{CrateId, FileId}; |
10 | use ra_syntax::{ast, SmolStr}; | 10 | use ra_syntax::ast; |
11 | use rustc_hash::{FxHashMap, FxHashSet}; | 11 | use rustc_hash::{FxHashMap, FxHashSet}; |
12 | use test_utils::tested_by; | 12 | use test_utils::tested_by; |
13 | 13 | ||
@@ -599,7 +599,7 @@ where | |||
599 | } | 599 | } |
600 | 600 | ||
601 | fn collect_module(&mut self, module: &raw::ModuleData, attrs: &Attrs) { | 601 | fn collect_module(&mut self, module: &raw::ModuleData, attrs: &Attrs) { |
602 | let path_attr = self.path_attr(attrs); | 602 | let path_attr = attrs.find_string_value("path"); |
603 | let is_macro_use = attrs.has_atom("macro_use"); | 603 | let is_macro_use = attrs.has_atom("macro_use"); |
604 | match module { | 604 | match module { |
605 | // inline module, just recurse | 605 | // inline module, just recurse |
@@ -612,7 +612,7 @@ where | |||
612 | module_id, | 612 | module_id, |
613 | file_id: self.file_id, | 613 | file_id: self.file_id, |
614 | raw_items: self.raw_items, | 614 | raw_items: self.raw_items, |
615 | mod_dir: self.mod_dir.descend_into_definition(name, path_attr), | 615 | mod_dir: self.mod_dir.descend_into_definition(name, path_attr.as_ref()), |
616 | } | 616 | } |
617 | .collect(&*items); | 617 | .collect(&*items); |
618 | if is_macro_use { | 618 | if is_macro_use { |
@@ -626,7 +626,7 @@ where | |||
626 | self.def_collector.db, | 626 | self.def_collector.db, |
627 | self.file_id, | 627 | self.file_id, |
628 | name, | 628 | name, |
629 | path_attr, | 629 | path_attr.as_ref(), |
630 | ) { | 630 | ) { |
631 | Ok((file_id, mod_dir)) => { | 631 | Ok((file_id, mod_dir)) => { |
632 | let module_id = self.push_child_module(name.clone(), ast_id, Some(file_id)); | 632 | let module_id = self.push_child_module(name.clone(), ast_id, Some(file_id)); |
@@ -798,10 +798,6 @@ where | |||
798 | fn is_cfg_enabled(&self, attrs: &Attrs) -> bool { | 798 | fn is_cfg_enabled(&self, attrs: &Attrs) -> bool { |
799 | attrs.iter().all(|attr| attr.is_cfg_enabled(&self.def_collector.cfg_options) != Some(false)) | 799 | attrs.iter().all(|attr| attr.is_cfg_enabled(&self.def_collector.cfg_options) != Some(false)) |
800 | } | 800 | } |
801 | |||
802 | fn path_attr<'a>(&self, attrs: &'a Attrs) -> Option<&'a SmolStr> { | ||
803 | attrs.iter().find_map(|attr| attr.as_path()) | ||
804 | } | ||
805 | } | 801 | } |
806 | 802 | ||
807 | fn is_macro_rules(path: &Path) -> bool { | 803 | fn is_macro_rules(path: &Path) -> bool { |