Skip to content

Commit 9e47488

Browse files
committed
Conditionally mark the test cfg as a well known cfg
1 parent 350fd28 commit 9e47488

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

src/cargo/core/compiler/mod.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,17 +1391,22 @@ fn check_cfg_args(unit: &Unit) -> Vec<OsString> {
13911391
}
13921392
arg_feature.push("))");
13931393

1394-
// In addition to the package features, we also include the `test` cfg (since
1395-
// compiler-team#785, as to be able to someday apply yt conditionaly), as well
1396-
// the `docsrs` cfg from the docs.rs service.
1394+
// In addition to the package features, we also conditionaly include the `test` cfg
1395+
// based on the unit target "test" field (ie `lib.test = false`, `[[bin]] test = false` and
1396+
// others).
13971397
//
1398-
// We include `docsrs` here (in Cargo) instead of rustc, since there is a much closer
1398+
// We also include `docsrs` here (in Cargo) instead of rustc, since there is a much closer
13991399
// relationship between Cargo and docs.rs than rustc and docs.rs. In particular, all
14001400
// users of docs.rs use Cargo, but not all users of rustc (like Rust-for-Linux) use docs.rs.
1401+
let arg_extra = if unit.target.tested() {
1402+
OsString::from("cfg(docsrs,test)")
1403+
} else {
1404+
OsString::from("cfg(docsrs)")
1405+
};
14011406

14021407
vec![
14031408
OsString::from("--check-cfg"),
1404-
OsString::from("cfg(docsrs,test)"),
1409+
arg_extra,
14051410
OsString::from("--check-cfg"),
14061411
arg_feature,
14071412
]

tests/testsuite/check_cfg.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -336,17 +336,18 @@ fn test_false_lib() {
336336
.build();
337337

338338
p.cargo("check -v")
339-
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs,test"))
339+
.with_stderr_does_not_contain(x!("rustc" => "cfg" of "docsrs,test"))
340+
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
340341
.run();
341342

342343
p.cargo("clean").run();
343344
p.cargo("test -v")
344-
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs,test"))
345+
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
345346
.run();
346347

347348
p.cargo("clean").run();
348349
p.cargo("test --lib -v")
349-
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs,test"))
350+
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
350351
.run();
351352
}
352353

@@ -372,7 +373,8 @@ fn test_false_bins() {
372373
.build();
373374

374375
p.cargo("check -v")
375-
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs,test")) // for foo & deamon
376+
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs,test")) // for foo
377+
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs")) // for deamon
376378
.run();
377379
}
378380

@@ -401,7 +403,8 @@ fn test_false_examples() {
401403
.build();
402404

403405
p.cargo("check --examples -v")
404-
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs,test"))
406+
.with_stderr_does_not_contain(x!("rustc" => "cfg" of "docsrs,test"))
407+
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
405408
.run();
406409
}
407410

0 commit comments

Comments
 (0)