@@ -732,7 +732,7 @@ fn prepare_rustdoc(build_runner: &BuildRunner<'_, '_>, unit: &Unit) -> CargoResu
732
732
let doc_dir = build_runner. files ( ) . out_dir ( unit) ;
733
733
rustdoc. arg ( "-o" ) . arg ( & doc_dir) ;
734
734
rustdoc. args ( & features_args ( unit) ) ;
735
- rustdoc. args ( & check_cfg_args ( build_runner , unit) ?) ;
735
+ rustdoc. args ( & check_cfg_args ( unit) ?) ;
736
736
737
737
add_error_format_and_color ( build_runner, & mut rustdoc) ;
738
738
add_allow_features ( build_runner, & mut rustdoc) ;
@@ -1125,7 +1125,7 @@ fn build_base_args(
1125
1125
}
1126
1126
1127
1127
cmd. args ( & features_args ( unit) ) ;
1128
- cmd. args ( & check_cfg_args ( build_runner , unit) ?) ;
1128
+ cmd. args ( & check_cfg_args ( unit) ?) ;
1129
1129
1130
1130
let meta = build_runner. files ( ) . metadata ( unit) ;
1131
1131
cmd. arg ( "-C" ) . arg ( & format ! ( "metadata={}" , meta) ) ;
@@ -1310,83 +1310,76 @@ fn trim_paths_args(
1310
1310
}
1311
1311
1312
1312
/// Generates the `--check-cfg` arguments for the `unit`.
1313
- fn check_cfg_args ( build_runner : & BuildRunner < ' _ , ' _ > , unit : & Unit ) -> CargoResult < Vec < OsString > > {
1314
- if build_runner
1315
- . bcx
1316
- . target_data
1317
- . info ( unit. kind )
1318
- . support_check_cfg
1319
- {
1320
- // The routine below generates the --check-cfg arguments. Our goals here are to
1321
- // enable the checking of conditionals and pass the list of declared features.
1322
- //
1323
- // In the simplified case, it would resemble something like this:
1324
- //
1325
- // --check-cfg=cfg() --check-cfg=cfg(feature, values(...))
1326
- //
1327
- // but having `cfg()` is redundant with the second argument (as well-known names
1328
- // and values are implicitly enabled when one or more `--check-cfg` argument is
1329
- // passed) so we don't emit it and just pass:
1330
- //
1331
- // --check-cfg=cfg(feature, values(...))
1332
- //
1333
- // This way, even if there are no declared features, the config `feature` will
1334
- // still be expected, meaning users would get "unexpected value" instead of name.
1335
- // This wasn't always the case, see rust-lang#119930 for some details.
1313
+ fn check_cfg_args ( unit : & Unit ) -> CargoResult < Vec < OsString > > {
1314
+ // The routine below generates the --check-cfg arguments. Our goals here are to
1315
+ // enable the checking of conditionals and pass the list of declared features.
1316
+ //
1317
+ // In the simplified case, it would resemble something like this:
1318
+ //
1319
+ // --check-cfg=cfg() --check-cfg=cfg(feature, values(...))
1320
+ //
1321
+ // but having `cfg()` is redundant with the second argument (as well-known names
1322
+ // and values are implicitly enabled when one or more `--check-cfg` argument is
1323
+ // passed) so we don't emit it and just pass:
1324
+ //
1325
+ // --check-cfg=cfg(feature, values(...))
1326
+ //
1327
+ // This way, even if there are no declared features, the config `feature` will
1328
+ // still be expected, meaning users would get "unexpected value" instead of name.
1329
+ // This wasn't always the case, see rust-lang#119930 for some details.
1336
1330
1337
- let gross_cap_estimation = unit. pkg . summary ( ) . features ( ) . len ( ) * 7 + 25 ;
1338
- let mut arg_feature = OsString :: with_capacity ( gross_cap_estimation) ;
1331
+ let gross_cap_estimation = unit. pkg . summary ( ) . features ( ) . len ( ) * 7 + 25 ;
1332
+ let mut arg_feature = OsString :: with_capacity ( gross_cap_estimation) ;
1339
1333
1340
- arg_feature. push ( "cfg(feature, values(" ) ;
1341
- for ( i, feature) in unit. pkg . summary ( ) . features ( ) . keys ( ) . enumerate ( ) {
1342
- if i != 0 {
1343
- arg_feature. push ( ", " ) ;
1344
- }
1345
- arg_feature. push ( "\" " ) ;
1346
- arg_feature. push ( feature) ;
1347
- arg_feature. push ( "\" " ) ;
1334
+ arg_feature. push ( "cfg(feature, values(" ) ;
1335
+ for ( i, feature) in unit. pkg . summary ( ) . features ( ) . keys ( ) . enumerate ( ) {
1336
+ if i != 0 {
1337
+ arg_feature. push ( ", " ) ;
1348
1338
}
1349
- arg_feature. push ( ")) " ) ;
1350
-
1351
- // We also include the `docsrs` cfg from the docs.rs service. We include it here
1352
- // (in Cargo) instead of rustc, since there is a much closer relationship between
1353
- // Cargo and docs.rs than rustc and docs.rs. In particular, all users of docs.rs use
1354
- // Cargo, but not all users of rustc (like Rust-for-Linux) use docs.rs.
1355
-
1356
- let mut args = vec ! [
1357
- OsString :: from ( "--check-cfg" ) ,
1358
- OsString :: from ( "cfg(docsrs)" ) ,
1359
- OsString :: from ( "--check-cfg" ) ,
1360
- arg_feature ,
1361
- ] ;
1362
-
1363
- // Also include the custom arguments specified in `[lints.rust.unexpected_cfgs.check_cfg]`
1364
- if let Ok ( Some ( lints ) ) = unit . pkg . manifest ( ) . resolved_toml ( ) . resolved_lints ( ) {
1365
- if let Some ( rust_lints ) = lints . get ( "rust" ) {
1366
- if let Some ( unexpected_cfgs ) = rust_lints . get ( "unexpected_cfgs" ) {
1367
- if let Some ( config ) = unexpected_cfgs. config ( ) {
1368
- if let Some ( check_cfg ) = config . get ( "check-cfg" ) {
1369
- if let Ok ( check_cfgs ) =
1370
- toml :: Value :: try_into :: < Vec < String > > ( check_cfg . clone ( ) )
1371
- {
1372
- for check_cfg in check_cfgs {
1373
- args . push ( OsString :: from ( "--check-cfg" ) ) ;
1374
- args . push ( OsString :: from ( check_cfg) ) ;
1375
- }
1376
- // error about `check-cfg` not being a list-of-string
1377
- } else {
1378
- bail ! ( "`lints.rust.unexpected_cfgs.check-cfg` must be a list of string" ) ;
1339
+ arg_feature. push ( "\" " ) ;
1340
+ arg_feature . push ( feature ) ;
1341
+ arg_feature . push ( " \" " ) ;
1342
+ }
1343
+ arg_feature . push ( "))" ) ;
1344
+
1345
+ // We also include the `docsrs` cfg from the docs.rs service. We include it here
1346
+ // (in Cargo) instead of rustc, since there is a much closer relationship between
1347
+ // Cargo and docs.rs than rustc and docs.rs. In particular, all users of docs.rs use
1348
+ // Cargo, but not all users of rustc (like Rust-for-Linux) use docs.rs.
1349
+
1350
+ let mut args = vec ! [
1351
+ OsString :: from ( "--check-cfg" ) ,
1352
+ OsString :: from ( "cfg(docsrs)" ) ,
1353
+ OsString :: from ( "--check-cfg" ) ,
1354
+ arg_feature ,
1355
+ ] ;
1356
+
1357
+ // Also include the custom arguments specified in `[lints.rust. unexpected_cfgs.check_cfg]`
1358
+ if let Ok ( Some ( lints ) ) = unit . pkg . manifest ( ) . resolved_toml ( ) . resolved_lints ( ) {
1359
+ if let Some ( rust_lints ) = lints . get ( "rust" ) {
1360
+ if let Some ( unexpected_cfgs ) = rust_lints . get ( "unexpected_cfgs" ) {
1361
+ if let Some ( config ) = unexpected_cfgs . config ( ) {
1362
+ if let Some ( check_cfg) = config . get ( "check-cfg" ) {
1363
+ if let Ok ( check_cfgs ) =
1364
+ toml :: Value :: try_into :: < Vec < String > > ( check_cfg. clone ( ) )
1365
+ {
1366
+ for check_cfg in check_cfgs {
1367
+ args . push ( OsString :: from ( "--check-cfg" ) ) ;
1368
+ args . push ( OsString :: from ( check_cfg ) ) ;
1379
1369
}
1370
+ // error about `check-cfg` not being a list-of-string
1371
+ } else {
1372
+ bail ! (
1373
+ "`lints.rust.unexpected_cfgs.check-cfg` must be a list of string"
1374
+ ) ;
1380
1375
}
1381
1376
}
1382
1377
}
1383
1378
}
1384
1379
}
1385
-
1386
- Ok ( args)
1387
- } else {
1388
- Ok ( Vec :: new ( ) )
1389
1380
}
1381
+
1382
+ Ok ( args)
1390
1383
}
1391
1384
1392
1385
/// Adds LTO related codegen flags.
0 commit comments