@@ -1401,19 +1401,28 @@ impl<'a> Builder<'a> {
1401
1401
rustflags. arg ( "-Zunstable-options" ) ;
1402
1402
}
1403
1403
1404
- // Enable cfg checking of cargo features for everything but std and also enable cfg
1405
- // checking of names and values.
1404
+ // #[cfg(bootstrap)] should remove every code path where it's false
1405
+ const USE_NEW_CHECK_CFG_SYNTAX : bool = false ;
1406
+
1407
+ // Enable compile-time checking of `cfg` names, values and Cargo `features`.
1406
1408
//
1407
1409
// Note: `std`, `alloc` and `core` imports some dependencies by #[path] (like
1408
1410
// backtrace, core_simd, std_float, ...), those dependencies have their own
1409
1411
// features but cargo isn't involved in the #[path] process and so cannot pass the
1410
1412
// complete list of features, so for that reason we don't enable checking of
1411
1413
// features for std crates.
1412
- cargo. arg ( if mode != Mode :: Std {
1413
- "-Zcheck-cfg=names,values,output,features"
1414
+ if USE_NEW_CHECK_CFG_SYNTAX {
1415
+ cargo. arg ( "-Zcheck-cfg" ) ;
1416
+ if mode == Mode :: Std {
1417
+ rustflags. arg ( "--check-cfg=cfg(feature,values(any()))" ) ;
1418
+ }
1414
1419
} else {
1415
- "-Zcheck-cfg=names,values,output"
1416
- } ) ;
1420
+ cargo. arg ( if mode != Mode :: Std {
1421
+ "-Zcheck-cfg=names,values,output,features"
1422
+ } else {
1423
+ "-Zcheck-cfg=names,values,output"
1424
+ } ) ;
1425
+ }
1417
1426
1418
1427
// Add extra cfg not defined in/by rustc
1419
1428
//
@@ -1433,7 +1442,12 @@ impl<'a> Builder<'a> {
1433
1442
. collect :: < String > ( ) ,
1434
1443
None => String :: new ( ) ,
1435
1444
} ;
1436
- rustflags. arg ( & format ! ( "--check-cfg=values({name}{values})" ) ) ;
1445
+ if USE_NEW_CHECK_CFG_SYNTAX {
1446
+ let values = values. strip_prefix ( "," ) . unwrap_or ( & values) ; // remove the first `,`
1447
+ rustflags. arg ( & format ! ( "--check-cfg=cfg({name},values({values}))" ) ) ;
1448
+ } else {
1449
+ rustflags. arg ( & format ! ( "--check-cfg=values({name}{values})" ) ) ;
1450
+ }
1437
1451
}
1438
1452
}
1439
1453
@@ -1449,7 +1463,11 @@ impl<'a> Builder<'a> {
1449
1463
// We also declare that the flag is expected, which we need to do to not
1450
1464
// get warnings about it being unexpected.
1451
1465
hostflags. arg ( "-Zunstable-options" ) ;
1452
- hostflags. arg ( "--check-cfg=values(bootstrap)" ) ;
1466
+ if USE_NEW_CHECK_CFG_SYNTAX {
1467
+ hostflags. arg ( "--check-cfg=cfg(bootstrap)" ) ;
1468
+ } else {
1469
+ hostflags. arg ( "--check-cfg=values(bootstrap)" ) ;
1470
+ }
1453
1471
1454
1472
// FIXME: It might be better to use the same value for both `RUSTFLAGS` and `RUSTDOCFLAGS`,
1455
1473
// but this breaks CI. At the very least, stage0 `rustdoc` needs `--cfg bootstrap`. See
0 commit comments