mirror of
https://github.com/rust-lang/cargo
synced 2024-10-13 11:12:25 +00:00
Auto merge of #13316 - Urgau:check-cfg-zero-features-2, r=epage
Go back to passing an empty `values()` when no features are declared This PR is basically a revert of https://github.com/rust-lang/cargo/pull/13011, which made the `--check-cfg` invocation be `cfg()` when no features are declared instead of `cfg(feature, values())` since it meant declaring that the config `feature` were to be available in this form: `#[cfg(feature)]`, which is not the case. Thankfully after some brainstorming, I [proposed](https://github.com/rust-lang/rust/pull/119930) changing the behavior of empty `values()` in `rustc` to no longer imply the _none_ value and simply create an empty set of expected values. 😃 For Cargo, always using `cfg(feature, values(...))` means that the config `feature` is always expected, regardless of the number of features. This makes the warning better, as it will now always be `unexpected config value` (instead of `unexpected config name`). 🎉 Fixes https://github.com/rust-lang/cargo/pull/13011#issuecomment-1819427800 as well as the concern in the [tracking issue](https://github.com/rust-lang/cargo/issues/10554). r? `@epage`
This commit is contained in:
commit
9574120bf0
|
@ -1270,23 +1270,18 @@ fn check_cfg_args(cx: &Context<'_, '_>, unit: &Unit) -> Vec<OsString> {
|
||||||
//
|
//
|
||||||
// but having `cfg()` is redundant with the second argument (as well-known names
|
// but having `cfg()` is redundant with the second argument (as well-known names
|
||||||
// and values are implicitly enabled when one or more `--check-cfg` argument is
|
// and values are implicitly enabled when one or more `--check-cfg` argument is
|
||||||
// passed) so we don't emit it:
|
// passed) so we don't emit it and just pass:
|
||||||
//
|
//
|
||||||
// --check-cfg=cfg(feature, values(...))
|
// --check-cfg=cfg(feature, values(...))
|
||||||
//
|
//
|
||||||
// expect when there are no features declared, where we can't generate the
|
// This way, even if there are no declared features, the config `feature` will
|
||||||
// `cfg(feature, values())` argument since it would mean that it is somehow
|
// still be expected, meaning users would get "unexpected value" instead of name.
|
||||||
// possible to have a `#[cfg(feature)]` without a feature name, which is
|
// This wasn't always the case, see rust-lang#119930 for some details.
|
||||||
// impossible and not what we want, so we just generate:
|
|
||||||
//
|
|
||||||
// --check-cfg=cfg()
|
|
||||||
|
|
||||||
let gross_cap_estimation = unit.pkg.summary().features().len() * 7 + 25;
|
let gross_cap_estimation = unit.pkg.summary().features().len() * 7 + 25;
|
||||||
let mut arg_feature = OsString::with_capacity(gross_cap_estimation);
|
let mut arg_feature = OsString::with_capacity(gross_cap_estimation);
|
||||||
|
|
||||||
arg_feature.push("cfg(");
|
arg_feature.push("cfg(feature, values(");
|
||||||
if !unit.pkg.summary().features().is_empty() {
|
|
||||||
arg_feature.push("feature, values(");
|
|
||||||
for (i, feature) in unit.pkg.summary().features().keys().enumerate() {
|
for (i, feature) in unit.pkg.summary().features().keys().enumerate() {
|
||||||
if i != 0 {
|
if i != 0 {
|
||||||
arg_feature.push(", ");
|
arg_feature.push(", ");
|
||||||
|
@ -1295,9 +1290,7 @@ fn check_cfg_args(cx: &Context<'_, '_>, unit: &Unit) -> Vec<OsString> {
|
||||||
arg_feature.push(feature);
|
arg_feature.push(feature);
|
||||||
arg_feature.push("\"");
|
arg_feature.push("\"");
|
||||||
}
|
}
|
||||||
arg_feature.push(")");
|
arg_feature.push("))");
|
||||||
}
|
|
||||||
arg_feature.push(")");
|
|
||||||
|
|
||||||
vec![
|
vec![
|
||||||
OsString::from("-Zunstable-options"),
|
OsString::from("-Zunstable-options"),
|
||||||
|
|
|
@ -15,16 +15,16 @@ macro_rules! x {
|
||||||
$what, '(', $($who,)* ')', "'", "[..]")
|
$what, '(', $($who,)* ')', "'", "[..]")
|
||||||
}
|
}
|
||||||
}};
|
}};
|
||||||
($tool:tt => $what:tt of $who:tt with $first_value:tt $($other_values:tt)*) => {{
|
($tool:tt => $what:tt of $who:tt with $($first_value:tt $($other_values:tt)*)?) => {{
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
{
|
{
|
||||||
concat!("[RUNNING] [..]", $tool, "[..] --check-cfg \"",
|
concat!("[RUNNING] [..]", $tool, "[..] --check-cfg \"",
|
||||||
$what, '(', $who, ", values(", "/\"", $first_value, "/\"", $(", ", "/\"", $other_values, "/\"",)* "))", '"', "[..]")
|
$what, '(', $who, ", values(", $("/\"", $first_value, "/\"", $(", ", "/\"", $other_values, "/\"",)*)* "))", '"', "[..]")
|
||||||
}
|
}
|
||||||
#[cfg(not(windows))]
|
#[cfg(not(windows))]
|
||||||
{
|
{
|
||||||
concat!("[RUNNING] [..]", $tool, "[..] --check-cfg '",
|
concat!("[RUNNING] [..]", $tool, "[..] --check-cfg '",
|
||||||
$what, '(', $who, ", values(", "\"", $first_value, "\"", $(", ", "\"", $other_values, "\"",)* "))", "'", "[..]")
|
$what, '(', $who, ", values(", $("\"", $first_value, "\"", $(", ", "\"", $other_values, "\"",)*)* "))", "'", "[..]")
|
||||||
}
|
}
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
@ -221,7 +221,7 @@ fn well_known_names_values() {
|
||||||
|
|
||||||
p.cargo("check -v -Zcheck-cfg")
|
p.cargo("check -v -Zcheck-cfg")
|
||||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
.masquerade_as_nightly_cargo(&["check-cfg"])
|
||||||
.with_stderr_contains(x!("rustc" => "cfg"))
|
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with))
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -284,7 +284,7 @@ fn well_known_names_values_test() {
|
||||||
|
|
||||||
p.cargo("test -v -Zcheck-cfg")
|
p.cargo("test -v -Zcheck-cfg")
|
||||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
.masquerade_as_nightly_cargo(&["check-cfg"])
|
||||||
.with_stderr_contains(x!("rustc" => "cfg"))
|
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with))
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -297,8 +297,8 @@ fn well_known_names_values_doctest() {
|
||||||
|
|
||||||
p.cargo("test -v --doc -Zcheck-cfg")
|
p.cargo("test -v --doc -Zcheck-cfg")
|
||||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
.masquerade_as_nightly_cargo(&["check-cfg"])
|
||||||
.with_stderr_contains(x!("rustc" => "cfg"))
|
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with))
|
||||||
.with_stderr_contains(x!("rustdoc" => "cfg"))
|
.with_stderr_contains(x!("rustdoc" => "cfg" of "feature" with))
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue