Skip to content

Commit 30a420d

Browse files
Urgaustupendoussuperpowers
authored andcommitted
Go back to passing an empty values() when no features are declared
See rust-lang/rust#119930
1 parent 16c8a22 commit 30a420d

File tree

2 files changed

+19
-26
lines changed

2 files changed

+19
-26
lines changed

src/cargo/core/compiler/mod.rs

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,34 +1270,27 @@ fn check_cfg_args(cx: &Context<'_, '_>, unit: &Unit) -> Vec<OsString> {
12701270
//
12711271
// but having `cfg()` is redundant with the second argument (as well-known names
12721272
// and values are implicitly enabled when one or more `--check-cfg` argument is
1273-
// passed) so we don't emit it:
1273+
// passed) so we don't emit it and just pass:
12741274
//
12751275
// --check-cfg=cfg(feature, values(...))
12761276
//
1277-
// expect when there are no features declared, where we can't generate the
1278-
// `cfg(feature, values())` argument since it would mean that it is somehow
1279-
// possible to have a `#[cfg(feature)]` without a feature name, which is
1280-
// impossible and not what we want, so we just generate:
1281-
//
1282-
// --check-cfg=cfg()
1277+
// This way, even if there are no declared features, the config `feature` will
1278+
// still be expected, meaning users would get "unexpected value" instead of name.
1279+
// This wasn't always the case, see rust-lang#119930 for some details.
12831280

12841281
let gross_cap_estimation = unit.pkg.summary().features().len() * 7 + 25;
12851282
let mut arg_feature = OsString::with_capacity(gross_cap_estimation);
12861283

1287-
arg_feature.push("cfg(");
1288-
if !unit.pkg.summary().features().is_empty() {
1289-
arg_feature.push("feature, values(");
1290-
for (i, feature) in unit.pkg.summary().features().keys().enumerate() {
1291-
if i != 0 {
1292-
arg_feature.push(", ");
1293-
}
1294-
arg_feature.push("\"");
1295-
arg_feature.push(feature);
1296-
arg_feature.push("\"");
1284+
arg_feature.push("cfg(feature, values(");
1285+
for (i, feature) in unit.pkg.summary().features().keys().enumerate() {
1286+
if i != 0 {
1287+
arg_feature.push(", ");
12971288
}
1298-
arg_feature.push(")");
1289+
arg_feature.push("\"");
1290+
arg_feature.push(feature);
1291+
arg_feature.push("\"");
12991292
}
1300-
arg_feature.push(")");
1293+
arg_feature.push("))");
13011294

13021295
vec![
13031296
OsString::from("-Zunstable-options"),

tests/testsuite/check_cfg.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ macro_rules! x {
1515
$what, '(', $($who,)* ')', "'", "[..]")
1616
}
1717
}};
18-
($tool:tt => $what:tt of $who:tt with $first_value:tt $($other_values:tt)*) => {{
18+
($tool:tt => $what:tt of $who:tt with $($first_value:tt $($other_values:tt)*)?) => {{
1919
#[cfg(windows)]
2020
{
2121
concat!("[RUNNING] [..]", $tool, "[..] --check-cfg \"",
22-
$what, '(', $who, ", values(", "/\"", $first_value, "/\"", $(", ", "/\"", $other_values, "/\"",)* "))", '"', "[..]")
22+
$what, '(', $who, ", values(", $("/\"", $first_value, "/\"", $(", ", "/\"", $other_values, "/\"",)*)* "))", '"', "[..]")
2323
}
2424
#[cfg(not(windows))]
2525
{
2626
concat!("[RUNNING] [..]", $tool, "[..] --check-cfg '",
27-
$what, '(', $who, ", values(", "\"", $first_value, "\"", $(", ", "\"", $other_values, "\"",)* "))", "'", "[..]")
27+
$what, '(', $who, ", values(", $("\"", $first_value, "\"", $(", ", "\"", $other_values, "\"",)*)* "))", "'", "[..]")
2828
}
2929
}};
3030
}
@@ -221,7 +221,7 @@ fn well_known_names_values() {
221221

222222
p.cargo("check -v -Zcheck-cfg")
223223
.masquerade_as_nightly_cargo(&["check-cfg"])
224-
.with_stderr_contains(x!("rustc" => "cfg"))
224+
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with))
225225
.run();
226226
}
227227

@@ -284,7 +284,7 @@ fn well_known_names_values_test() {
284284

285285
p.cargo("test -v -Zcheck-cfg")
286286
.masquerade_as_nightly_cargo(&["check-cfg"])
287-
.with_stderr_contains(x!("rustc" => "cfg"))
287+
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with))
288288
.run();
289289
}
290290

@@ -297,8 +297,8 @@ fn well_known_names_values_doctest() {
297297

298298
p.cargo("test -v --doc -Zcheck-cfg")
299299
.masquerade_as_nightly_cargo(&["check-cfg"])
300-
.with_stderr_contains(x!("rustc" => "cfg"))
301-
.with_stderr_contains(x!("rustdoc" => "cfg"))
300+
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with))
301+
.with_stderr_contains(x!("rustdoc" => "cfg" of "feature" with))
302302
.run();
303303
}
304304

0 commit comments

Comments
 (0)