From 4b74fb1d896ce5a1c8c4c4bf73ad2940fb86abc5 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 24 Nov 2019 16:03:02 +0300 Subject: Nicer API for attrs --- crates/ra_hir_def/src/nameres/collector.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'crates/ra_hir_def/src/nameres') diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index 15941a1cb..7a5f90327 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs @@ -599,8 +599,8 @@ where } fn collect_module(&mut self, module: &raw::ModuleData, attrs: &Attrs) { - let path_attr = attrs.find_string_value("path"); - let is_macro_use = attrs.has_atom("macro_use"); + let path_attr = attrs.by_key("path").string_value(); + let is_macro_use = attrs.by_key("macro_use").exists(); match module { // inline module, just recurse raw::ModuleData::Definition { name, items, ast_id } => { @@ -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.as_ref()), + mod_dir: self.mod_dir.descend_into_definition(name, path_attr), } .collect(&*items); if is_macro_use { @@ -626,7 +626,7 @@ where self.def_collector.db, self.file_id, name, - path_attr.as_ref(), + path_attr, ) { Ok((file_id, mod_dir)) => { let module_id = self.push_child_module(name.clone(), ast_id, Some(file_id)); @@ -796,7 +796,11 @@ where } fn is_cfg_enabled(&self, attrs: &Attrs) -> bool { - attrs.iter().all(|attr| attr.is_cfg_enabled(&self.def_collector.cfg_options) != Some(false)) + // FIXME: handle cfg_attr :-) + attrs + .by_key("cfg") + .tt_values() + .all(|tt| self.def_collector.cfg_options.is_cfg_enabled(tt) != Some(false)) } } -- cgit v1.2.3