Add support for values() with --check-cfg

This commit is contained in:
Loïc BRANSTETT 2022-02-25 13:43:57 +01:00
parent 2f8d1a835b
commit 50e61a1a66
4 changed files with 13 additions and 5 deletions

View File

@ -207,6 +207,9 @@ pub fn parse_check_cfg(specs: Vec<String>) -> CheckCfg {
"`values()` first argument must be a simple identifer"
);
}
} else if args.is_empty() {
cfg.well_known_values = true;
continue 'specs;
}
}
}

View File

@ -1025,13 +1025,19 @@ pub fn to_crate_config(cfg: FxHashSet<(String, Option<String>)>) -> CrateConfig
pub struct CheckCfg<T = String> {
/// The set of all `names()`, if None no name checking is performed
pub names_valid: Option<FxHashSet<T>>,
/// Is well known values activated
pub well_known_values: bool,
/// The set of all `values()`
pub values_valid: FxHashMap<T, FxHashSet<T>>,
}
impl<T> Default for CheckCfg<T> {
fn default() -> Self {
CheckCfg { names_valid: Default::default(), values_valid: Default::default() }
CheckCfg {
names_valid: Default::default(),
values_valid: Default::default(),
well_known_values: false,
}
}
}
@ -1047,6 +1053,7 @@ impl<T> CheckCfg<T> {
.iter()
.map(|(a, b)| (f(a), b.iter().map(|b| f(b)).collect()))
.collect(),
well_known_values: self.well_known_values,
}
}
}

View File

@ -1,6 +1,6 @@
// Check that a an empty values() is rejected
// Check that a an empty values() pass
//
// check-fail
// check-pass
// compile-flags: --check-cfg=values() -Z unstable-options
fn main() {}

View File

@ -1,2 +0,0 @@
error: invalid `--check-cfg` argument: `values()` (expected `names(name1, name2, ... nameN)` or `values(name, "value1", "value2", ... "valueN")`)