Skip to content

Commit 756af9d

Browse files
authored
Rollup merge of #125818 - Urgau:print-check-cfg-no-values, r=petrochenkov
Handle no values cfgs with `--print=check-cfg` This PR fix a bug with `--print=check-cfg`, where no values cfgs where not printed since we only printed cfgs that had at least one values. The representation I choose is `CFG=`, since it doesn't correspond to any valid config, it also IMO nicely complements the `values()` (to indicate no values). Representing the absence of value by the absence of the value. So for `cfg(feature, values())` we would print `feature=`. I also added the missing tracking issue number in the doc. r? ```@petrochenkov```
2 parents b477f89 + f58bf91 commit 756af9d

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
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

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# `print=check-cfg`
22

3-
The tracking issue for this feature is: [#XXXXXX](https://github.com/rust-lang/rust/issues/XXXXXX).
3+
The tracking issue for this feature is: [#125704](https://github.com/rust-lang/rust/issues/125704).
44

55
------------------------
66

@@ -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)