Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-expand/src/cfg_process.rs')
-rw-r--r--crates/hir-expand/src/cfg_process.rs25
1 files changed, 15 insertions, 10 deletions
diff --git a/crates/hir-expand/src/cfg_process.rs b/crates/hir-expand/src/cfg_process.rs
index 5f038cfe68..9f92718419 100644
--- a/crates/hir-expand/src/cfg_process.rs
+++ b/crates/hir-expand/src/cfg_process.rs
@@ -3,6 +3,7 @@ use std::iter::Peekable;
use base_db::CrateId;
use cfg::{CfgAtom, CfgExpr};
+use intern::{sym, Symbol};
use rustc_hash::FxHashSet;
use syntax::{
ast::{self, Attr, HasAttrs, Meta, VariantList},
@@ -262,13 +263,13 @@ where
let name = match iter.next() {
None => return None,
Some(NodeOrToken::Token(element)) => match element.kind() {
- syntax::T![ident] => element.text().to_owned(),
+ syntax::T![ident] => Symbol::intern(element.text()),
_ => return Some(CfgExpr::Invalid),
},
Some(_) => return Some(CfgExpr::Invalid),
};
- let result = match name.as_str() {
- "all" | "any" | "not" => {
+ let result = match &name {
+ s if [&sym::all, &sym::any, &sym::not].contains(&s) => {
let mut preds = Vec::new();
let Some(NodeOrToken::Node(tree)) = iter.next() else {
return Some(CfgExpr::Invalid);
@@ -285,10 +286,12 @@ where
preds.push(pred);
}
}
- let group = match name.as_str() {
- "all" => CfgExpr::All(preds),
- "any" => CfgExpr::Any(preds),
- "not" => CfgExpr::Not(Box::new(preds.pop().unwrap_or(CfgExpr::Invalid))),
+ let group = match &name {
+ s if *s == sym::all => CfgExpr::All(preds),
+ s if *s == sym::any => CfgExpr::Any(preds),
+ s if *s == sym::not => {
+ CfgExpr::Not(Box::new(preds.pop().unwrap_or(CfgExpr::Invalid)))
+ }
_ => unreachable!(),
};
Some(group)
@@ -301,13 +304,15 @@ where
if (value_token.kind() == syntax::SyntaxKind::STRING) =>
{
let value = value_token.text();
- let value = value.trim_matches('"').into();
- Some(CfgExpr::Atom(CfgAtom::KeyValue { key: name.into(), value }))
+ Some(CfgExpr::Atom(CfgAtom::KeyValue {
+ key: name,
+ value: Symbol::intern(value.trim_matches('"')),
+ }))
}
_ => None,
}
}
- _ => Some(CfgExpr::Atom(CfgAtom::Flag(name.into()))),
+ _ => Some(CfgExpr::Atom(CfgAtom::Flag(name))),
},
};
if let Some(NodeOrToken::Token(element)) = iter.peek() {