From 38e38d9b290ff90973c25a06962b81dbbb5d3d9e Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 23 Jul 2020 16:22:17 +0200 Subject: Cleanup CFG API --- crates/ra_hir_def/src/attr.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'crates/ra_hir_def/src/attr.rs') diff --git a/crates/ra_hir_def/src/attr.rs b/crates/ra_hir_def/src/attr.rs index e228e2145..70ccd4305 100644 --- a/crates/ra_hir_def/src/attr.rs +++ b/crates/ra_hir_def/src/attr.rs @@ -5,7 +5,7 @@ use std::{ops, sync::Arc}; use either::Either; use hir_expand::{hygiene::Hygiene, AstId, InFile}; use mbe::ast_to_token_tree; -use ra_cfg::CfgOptions; +use ra_cfg::{CfgExpr, CfgOptions}; use ra_syntax::{ ast::{self, AstNode, AttrsOwner}, SmolStr, @@ -125,9 +125,12 @@ impl Attrs { AttrQuery { attrs: self, key } } - pub(crate) fn is_cfg_enabled(&self, cfg_options: &CfgOptions) -> bool { + pub fn cfg(&self) -> impl Iterator + '_ { // FIXME: handle cfg_attr :-) - self.by_key("cfg").tt_values().all(|tt| cfg_options.is_cfg_enabled(tt) != Some(false)) + self.by_key("cfg").tt_values().map(CfgExpr::parse) + } + pub(crate) fn is_cfg_enabled(&self, cfg_options: &CfgOptions) -> bool { + self.cfg().all(|cfg| cfg_options.check(&cfg) != Some(false)) } } -- cgit v1.2.3