Skip to content

Commit

Permalink
Handle no values cfg with --print=check-cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
Urgau committed May 31, 2024
1 parent 5870f1c commit ec8fce4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
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
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 15 additions & 0 deletions tests/run-make/print-check-cfg/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,21 @@ fn main() {
/*has_any_any*/ false,
/*contains*/ &["unix", "miri", "feature"],
);
check(
/*args*/ &["--check-cfg=cfg(feature, values())"],
/*has_any*/ false,
/*has_any_any*/ false,
/*contains*/ &["feature="],
);
check(
/*args*/ &[
"--check-cfg=cfg(feature, values())",
"--check-cfg=cfg(feature, values(none()))"
],
/*has_any*/ false,
/*has_any_any*/ false,
/*contains*/ &["feature"],
);
check(
/*args*/ &[r#"--check-cfg=cfg(feature, values(none(), "", "test", "lol"))"#],
/*has_any*/ false,
Expand Down

0 comments on commit ec8fce4

Please sign in to comment.