Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle no values cfgs with --print=check-cfg #125818

Merged
merged 2 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions compiler/rustc_driver_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -814,13 +814,17 @@ fn print_crate_info(
match expected_values {
ExpectedValues::Any => check_cfgs.push(format!("{name}=any()")),
ExpectedValues::Some(values) => {
check_cfgs.extend(values.iter().map(|value| {
if let Some(value) = value {
format!("{name}=\"{value}\"")
} else {
name.to_string()
}
}))
if !values.is_empty() {
check_cfgs.extend(values.iter().map(|value| {
if let Some(value) = value {
format!("{name}=\"{value}\"")
} else {
name.to_string()
}
}))
} else {
check_cfgs.push(format!("{name}="))
}
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/doc/unstable-book/src/compiler-flags/print-check-cfg.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# `print=check-cfg`

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

------------------------

Expand All @@ -15,6 +15,7 @@ This print option works similarly to `--print=cfg` (modulo check-cfg specifics):
- `cfg(feature, values("foo", "bar"))`: `feature="foo"` and `feature="bar"`
- `cfg(feature, values(none(), ""))`: `feature` and `feature=""`
- `cfg(feature, values(any()))`: `feature=any()`
- `cfg(feature, values())`: `feature=`
- `cfg(any())`: `any()`
- *nothing*: `any()=any()`

Expand Down
14 changes: 14 additions & 0 deletions tests/run-make/print-check-cfg/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@ fn main() {
doesnt_contain: &["any()", "any()=any()", "feature=none()", "feature="],
},
});
check(CheckCfg {
args: &["--check-cfg=cfg(feature, values())"],
contains: Contains::Some {
contains: &["feature="],
doesnt_contain: &["any()", "any()=any()", "feature=none()", "feature"],
},
});
check(CheckCfg {
args: &["--check-cfg=cfg(feature, values())", "--check-cfg=cfg(feature, values(none()))"],
contains: Contains::Some {
contains: &["feature"],
doesnt_contain: &["any()", "any()=any()", "feature=none()", "feature="],
},
});
check(CheckCfg {
args: &[
r#"--check-cfg=cfg(feature, values(any()))"#,
Expand Down
Loading