From 831bb1cf91d69e7e325ecbdab11e6fc80bcae4a4 Mon Sep 17 00:00:00 2001 From: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> Date: Tue, 5 May 2020 09:34:07 +0200 Subject: refactor: use attrsOwner directly in is_cfg_enabled Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> --- crates/ra_hir_def/src/adt.rs | 17 ++++++++--------- crates/ra_hir_def/src/body.rs | 11 ++++------- crates/ra_hir_def/src/body/lower.rs | 6 ++---- crates/ra_hir_def/src/data.rs | 3 +-- 4 files changed, 15 insertions(+), 22 deletions(-) (limited to 'crates/ra_hir_def') diff --git a/crates/ra_hir_def/src/adt.rs b/crates/ra_hir_def/src/adt.rs index d0912ddaa..2bc34d449 100644 --- a/crates/ra_hir_def/src/adt.rs +++ b/crates/ra_hir_def/src/adt.rs @@ -118,11 +118,12 @@ fn lower_enum( module_id: ModuleId, ) { let expander = CfgExpander::new(db, ast.file_id, module_id.krate); - let variants = - ast.value.variant_list().into_iter().flat_map(|it| it.variants()).filter(|var| { - let attrs = expander.parse_attrs(var); - expander.is_cfg_enabled(&attrs) - }); + let variants = ast + .value + .variant_list() + .into_iter() + .flat_map(|it| it.variants()) + .filter(|var| expander.is_cfg_enabled(var)); for var in variants { trace.alloc( || var.clone(), @@ -215,8 +216,7 @@ fn lower_struct( match &ast.value { ast::StructKind::Tuple(fl) => { for (i, fd) in fl.fields().enumerate() { - let attrs = expander.parse_attrs(&fd); - if !expander.is_cfg_enabled(&attrs) { + if !expander.is_cfg_enabled(&fd) { continue; } @@ -233,8 +233,7 @@ fn lower_struct( } ast::StructKind::Record(fl) => { for fd in fl.fields() { - let attrs = expander.parse_attrs(&fd); - if !expander.is_cfg_enabled(&attrs) { + if !expander.is_cfg_enabled(&fd) { continue; } diff --git a/crates/ra_hir_def/src/body.rs b/crates/ra_hir_def/src/body.rs index 4edaad960..f5a7305dc 100644 --- a/crates/ra_hir_def/src/body.rs +++ b/crates/ra_hir_def/src/body.rs @@ -60,7 +60,8 @@ impl CfgExpander { Attrs::new(owner, &self.hygiene) } - pub(crate) fn is_cfg_enabled(&self, attrs: &Attrs) -> bool { + pub(crate) fn is_cfg_enabled(&self, owner: &dyn ast::AttrsOwner) -> bool { + let attrs = self.parse_attrs(owner); attrs.is_cfg_enabled(&self.cfg_options) } } @@ -141,12 +142,8 @@ impl Expander { InFile { file_id: self.current_file_id, value } } - pub(crate) fn parse_attrs(&self, owner: &dyn ast::AttrsOwner) -> Attrs { - self.cfg_expander.parse_attrs(owner) - } - - pub(crate) fn is_cfg_enabled(&self, attrs: &Attrs) -> bool { - self.cfg_expander.is_cfg_enabled(attrs) + pub(crate) fn is_cfg_enabled(&self, owner: &dyn ast::AttrsOwner) -> bool { + self.cfg_expander.is_cfg_enabled(owner) } fn parse_path(&mut self, path: ast::Path) -> Option { diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index 687216dc3..8f5fa1b55 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs @@ -162,8 +162,7 @@ impl ExprCollector<'_> { fn collect_expr(&mut self, expr: ast::Expr) -> ExprId { let syntax_ptr = AstPtr::new(&expr); - let attrs = self.expander.parse_attrs(&expr); - if !self.expander.is_cfg_enabled(&attrs) { + if !self.expander.is_cfg_enabled(&expr) { return self.missing_expr(); } match expr { @@ -329,8 +328,7 @@ impl ExprCollector<'_> { .fields() .inspect(|field| field_ptrs.push(AstPtr::new(field))) .filter_map(|field| { - let attrs = self.expander.parse_attrs(&field); - if !self.expander.is_cfg_enabled(&attrs) { + if !self.expander.is_cfg_enabled(&field) { return None; } let name = field.field_name()?.as_name(); diff --git a/crates/ra_hir_def/src/data.rs b/crates/ra_hir_def/src/data.rs index d4cba4d05..2dbae04d3 100644 --- a/crates/ra_hir_def/src/data.rs +++ b/crates/ra_hir_def/src/data.rs @@ -335,8 +335,7 @@ fn collect_items( .filter_map(|item_node| match item_node { ast::ImplItem::FnDef(it) => { let name = it.name().map_or_else(Name::missing, |it| it.as_name()); - let attrs = expander.parse_attrs(&it); - if !expander.is_cfg_enabled(&attrs) { + if !expander.is_cfg_enabled(&it) { return None; } let def = FunctionLoc { container, ast_id: AstId::new(file_id, items.ast_id(&it)) } -- cgit v1.2.3