Skip to content

Commit ec8fce4

Browse files
committed
Handle no values cfg with --print=check-cfg
1 parent 5870f1c commit ec8fce4

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

compiler/rustc_driver_impl/src/lib.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -814,13 +814,17 @@ fn print_crate_info(
814814
match expected_values {
815815
ExpectedValues::Any => check_cfgs.push(format!("{name}=any()")),
816816
ExpectedValues::Some(values) => {
817-
check_cfgs.extend(values.iter().map(|value| {
818-
if let Some(value) = value {
819-
format!("{name}=\"{value}\"")
820-
} else {
821-
name.to_string()
822-
}
823-
}))
817+
if !values.is_empty() {
818+
check_cfgs.extend(values.iter().map(|value| {
819+
if let Some(value) = value {
820+
format!("{name}=\"{value}\"")
821+
} else {
822+
name.to_string()
823+
}
824+
}))
825+
} else {
826+
check_cfgs.push(format!("{name}="))
827+
}
824828
}
825829
}
826830
}

src/doc/unstable-book/src/compiler-flags/print-check-cfg.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ This print option works similarly to `--print=cfg` (modulo check-cfg specifics):
1515
- `cfg(feature, values("foo", "bar"))`: `feature="foo"` and `feature="bar"`
1616
- `cfg(feature, values(none(), ""))`: `feature` and `feature=""`
1717
- `cfg(feature, values(any()))`: `feature=any()`
18+
- `cfg(feature, values())`: `feature=`
1819
- `cfg(any())`: `any()`
1920
- *nothing*: `any()=any()`
2021

tests/run-make/print-check-cfg/rmake.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,21 @@ fn main() {
3333
/*has_any_any*/ false,
3434
/*contains*/ &["unix", "miri", "feature"],
3535
);
36+
check(
37+
/*args*/ &["--check-cfg=cfg(feature, values())"],
38+
/*has_any*/ false,
39+
/*has_any_any*/ false,
40+
/*contains*/ &["feature="],
41+
);
42+
check(
43+
/*args*/ &[
44+
"--check-cfg=cfg(feature, values())",
45+
"--check-cfg=cfg(feature, values(none()))"
46+
],
47+
/*has_any*/ false,
48+
/*has_any_any*/ false,
49+
/*contains*/ &["feature"],
50+
);
3651
check(
3752
/*args*/ &[r#"--check-cfg=cfg(feature, values(none(), "", "test", "lol"))"#],
3853
/*has_any*/ false,

0 commit comments

Comments
 (0)