This commit is contained in:
Aleksey Kladov 2019-11-24 15:28:45 +03:00
parent 151180057b
commit 8e36cb5860
2 changed files with 5 additions and 19 deletions

View File

@ -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<bool> {
pub(crate) fn is_cfg_enabled(&self, cfg_options: &CfgOptions) -> Option<bool> {
cfg_options.is_cfg_enabled(self.as_cfg()?)
}
}

View File

@ -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 {