From 8e36cb586038e2c12e6eceae57f7a95684fc6c6d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 24 Nov 2019 15:28:45 +0300 Subject: [PATCH] Simplify --- crates/ra_hir_def/src/attr.rs | 12 +----------- 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 87f41159952..7d8f0d915e6 100644 --- a/crates/ra_hir_def/src/attr.rs +++ b/crates/ra_hir_def/src/attr.rs @@ -144,17 +144,7 @@ impl Attr { } } - pub fn as_path(&self) -> Option<&SmolStr> { - if !self.is_simple_atom("path") { - return None; - } - match &self.input { - Some(AttrInput::Literal(it)) => Some(it), - _ => None, - } - } - - pub fn is_cfg_enabled(&self, cfg_options: &CfgOptions) -> Option { + pub(crate) fn is_cfg_enabled(&self, cfg_options: &CfgOptions) -> Option { cfg_options.is_cfg_enabled(self.as_cfg()?) } } diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index 7b248799979..15941a1cb7c 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::{ }; use ra_cfg::CfgOptions; use ra_db::{CrateId, FileId}; -use ra_syntax::{ast, SmolStr}; +use ra_syntax::ast; use rustc_hash::{FxHashMap, FxHashSet}; use test_utils::tested_by; @@ -599,7 +599,7 @@ where } fn collect_module(&mut self, module: &raw::ModuleData, attrs: &Attrs) { - let path_attr = self.path_attr(attrs); + let path_attr = attrs.find_string_value("path"); let is_macro_use = attrs.has_atom("macro_use"); match module { // inline module, just recurse @@ -612,7 +612,7 @@ where module_id, file_id: self.file_id, raw_items: self.raw_items, - mod_dir: self.mod_dir.descend_into_definition(name, path_attr), + mod_dir: self.mod_dir.descend_into_definition(name, path_attr.as_ref()), } .collect(&*items); if is_macro_use { @@ -626,7 +626,7 @@ where self.def_collector.db, self.file_id, name, - path_attr, + path_attr.as_ref(), ) { Ok((file_id, mod_dir)) => { let module_id = self.push_child_module(name.clone(), ast_id, Some(file_id)); @@ -798,10 +798,6 @@ where fn is_cfg_enabled(&self, attrs: &Attrs) -> bool { attrs.iter().all(|attr| attr.is_cfg_enabled(&self.def_collector.cfg_options) != Some(false)) } - - fn path_attr<'a>(&self, attrs: &'a Attrs) -> Option<&'a SmolStr> { - attrs.iter().find_map(|attr| attr.as_path()) - } } fn is_macro_rules(path: &Path) -> bool {