Rust: turn off the test cfg by default

This commit is contained in:
Paolo Tranquilli
2024-11-08 17:07:03 +01:00
parent a13c70bd11
commit f77f2b7ff0
4 changed files with 20 additions and 5 deletions

View File

@@ -137,13 +137,20 @@ fn to_cfg_override(spec: &str) -> CfgAtom {
fn to_cfg_overrides(specs: &Vec<String>) -> CfgOverrides {
let mut enabled_cfgs = Vec::new();
let mut disabled_cfgs = Vec::new();
let mut has_test_explicitly_enabled = false;
for spec in specs {
if spec.starts_with("-") {
disabled_cfgs.push(to_cfg_override(&spec[1..]));
} else {
enabled_cfgs.push(to_cfg_override(spec));
if spec == "test" {
has_test_explicitly_enabled = true;
}
}
}
if !has_test_explicitly_enabled {
disabled_cfgs.push(to_cfg_override("test"));
}
if let Some(global) = CfgDiff::new(enabled_cfgs, disabled_cfgs) {
CfgOverrides {
global,
@@ -151,6 +158,10 @@ fn to_cfg_overrides(specs: &Vec<String>) -> CfgOverrides {
}
} else {
warn!("non-disjoint cfg overrides, ignoring: {}", specs.join(", "));
CfgOverrides::default()
CfgOverrides {
global: CfgDiff::new(Vec::new(), vec![to_cfg_override("test")])
.expect("disabling one cfg should always succeed"),
..Default::default()
}
}
}