Skip to content

Commit 5f0043a

Browse files
committed
Handle no values cfg with --print=check-cfg
1 parent a83cf56 commit 5f0043a

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

compiler/rustc_driver_impl/src/lib.rs

+11-7
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

+1
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

+14
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,20 @@ fn main() {
4848
doesnt_contain: &["any()", "any()=any()", "feature=none()", "feature="],
4949
},
5050
});
51+
check(CheckCfg {
52+
args: &["--check-cfg=cfg(feature, values())"],
53+
contains: Contains::Some {
54+
contains: &["feature="],
55+
doesnt_contain: &["any()", "any()=any()", "feature=none()", "feature"],
56+
},
57+
});
58+
check(CheckCfg {
59+
args: &["--check-cfg=cfg(feature, values())", "--check-cfg=cfg(feature, values(none()))"],
60+
contains: Contains::Some {
61+
contains: &["feature"],
62+
doesnt_contain: &["any()", "any()=any()", "feature=none()", "feature="],
63+
},
64+
});
5165
check(CheckCfg {
5266
args: &[
5367
r#"--check-cfg=cfg(feature, values(any()))"#,

0 commit comments

Comments
 (0)