Improve CheckCfg internal representation
This commit is contained in:
parent
cb4ee81ef5
commit
da896d35f4
3 changed files with 58 additions and 43 deletions
|
@ -169,11 +169,12 @@ pub fn parse_check_cfg(specs: Vec<String>) -> CheckCfg {
|
|||
Ok(meta_item) if parser.token == token::Eof => {
|
||||
if let Some(args) = meta_item.meta_item_list() {
|
||||
if meta_item.has_name(sym::names) {
|
||||
cfg.names_checked = true;
|
||||
let names_valid =
|
||||
cfg.names_valid.get_or_insert_with(|| FxHashSet::default());
|
||||
for arg in args {
|
||||
if arg.is_word() && arg.ident().is_some() {
|
||||
let ident = arg.ident().expect("multi-segment cfg key");
|
||||
cfg.names_valid.insert(ident.name.to_string());
|
||||
names_valid.insert(ident.name.to_string());
|
||||
} else {
|
||||
error!("`names()` arguments must be simple identifers");
|
||||
}
|
||||
|
@ -182,14 +183,19 @@ pub fn parse_check_cfg(specs: Vec<String>) -> CheckCfg {
|
|||
} else if meta_item.has_name(sym::values) {
|
||||
if let Some((name, values)) = args.split_first() {
|
||||
if name.is_word() && name.ident().is_some() {
|
||||
let values_valid = cfg
|
||||
.values_valid
|
||||
.get_or_insert_with(|| FxHashMap::default());
|
||||
let ident = name.ident().expect("multi-segment cfg key");
|
||||
cfg.values_checked.insert(ident.to_string());
|
||||
let ident_values = values_valid
|
||||
.entry(ident.to_string())
|
||||
.or_insert_with(|| FxHashSet::default());
|
||||
|
||||
for val in values {
|
||||
if let Some(LitKind::Str(s, _)) =
|
||||
val.literal().map(|lit| &lit.kind)
|
||||
{
|
||||
cfg.values_valid
|
||||
.insert((ident.to_string(), s.to_string()));
|
||||
ident_values.insert(s.to_string());
|
||||
} else {
|
||||
error!(
|
||||
"`values()` arguments must be string literals"
|
||||
|
@ -219,7 +225,11 @@ pub fn parse_check_cfg(specs: Vec<String>) -> CheckCfg {
|
|||
);
|
||||
}
|
||||
|
||||
cfg.names_valid.extend(cfg.values_checked.iter().cloned());
|
||||
if let Some(values_valid) = &cfg.values_valid {
|
||||
if let Some(names_valid) = &mut cfg.names_valid {
|
||||
names_valid.extend(values_valid.keys().cloned());
|
||||
}
|
||||
}
|
||||
cfg
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue