From 5720eb77dbd6e650c36d7691c962e273f893a0ca Mon Sep 17 00:00:00 2001 From: Urgau Date: Thu, 19 Dec 2024 20:41:23 +0100 Subject: [PATCH] Add the `test` cfg as a well known cfg before of compiler change --- src/cargo/core/compiler/mod.rs | 13 ++++++++----- tests/testsuite/check_cfg.rs | 30 +++++++++++++++--------------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/cargo/core/compiler/mod.rs b/src/cargo/core/compiler/mod.rs index 93859e914b9..277039685d6 100644 --- a/src/cargo/core/compiler/mod.rs +++ b/src/cargo/core/compiler/mod.rs @@ -1391,14 +1391,17 @@ fn check_cfg_args(unit: &Unit) -> Vec { } arg_feature.push("))"); - // We also include the `docsrs` cfg from the docs.rs service. We include it here - // (in Cargo) instead of rustc, since there is a much closer relationship between - // Cargo and docs.rs than rustc and docs.rs. In particular, all users of docs.rs use - // Cargo, but not all users of rustc (like Rust-for-Linux) use docs.rs. + // In addition to the package features, we also include the `test` cfg (since + // compiler-team#785, as to be able to someday apply yt conditionaly), as well + // the `docsrs` cfg from the docs.rs service. + // + // We include `docsrs` here (in Cargo) instead of rustc, since there is a much closer + // relationship between Cargo and docs.rs than rustc and docs.rs. In particular, all + // users of docs.rs use Cargo, but not all users of rustc (like Rust-for-Linux) use docs.rs. vec![ OsString::from("--check-cfg"), - OsString::from("cfg(docsrs)"), + OsString::from("cfg(docsrs,test)"), OsString::from("--check-cfg"), arg_feature, ] diff --git a/tests/testsuite/check_cfg.rs b/tests/testsuite/check_cfg.rs index dc34b13f0c1..2e03254337a 100644 --- a/tests/testsuite/check_cfg.rs +++ b/tests/testsuite/check_cfg.rs @@ -51,7 +51,7 @@ fn features() { p.cargo("check -v") .with_stderr_contains(x!("rustc" => "cfg" of "feature" with "f_a" "f_b")) - .with_stderr_contains(x!("rustc" => "cfg" of "docsrs")) + .with_stderr_contains(x!("rustc" => "cfg" of "docsrs,test")) .run(); } @@ -81,7 +81,7 @@ fn features_with_deps() { p.cargo("check -v") .with_stderr_contains(x!("rustc" => "cfg" of "feature" with "f_a" "f_b")) - .with_stderr_contains(x!("rustc" => "cfg" of "docsrs")) + .with_stderr_contains(x!("rustc" => "cfg" of "docsrs,test")) .run(); } @@ -112,7 +112,7 @@ fn features_with_opt_deps() { p.cargo("check -v") .with_stderr_contains(x!("rustc" => "cfg" of "feature" with "bar" "default" "f_a" "f_b")) - .with_stderr_contains(x!("rustc" => "cfg" of "docsrs")) + .with_stderr_contains(x!("rustc" => "cfg" of "docsrs,test")) .run(); } @@ -142,7 +142,7 @@ fn features_with_namespaced_features() { p.cargo("check -v") .with_stderr_contains(x!("rustc" => "cfg" of "feature" with "f_a" "f_b")) - .with_stderr_contains(x!("rustc" => "cfg" of "docsrs")) + .with_stderr_contains(x!("rustc" => "cfg" of "docsrs,test")) .run(); } @@ -232,7 +232,7 @@ fn well_known_names_values() { p.cargo("check -v") .with_stderr_contains(x!("rustc" => "cfg" of "feature" with)) - .with_stderr_contains(x!("rustc" => "cfg" of "docsrs")) + .with_stderr_contains(x!("rustc" => "cfg" of "docsrs,test")) .run(); } @@ -257,7 +257,7 @@ fn features_test() { p.cargo("test -v") .with_stderr_contains(x!("rustc" => "cfg" of "feature" with "f_a" "f_b")) - .with_stderr_contains(x!("rustc" => "cfg" of "docsrs")) + .with_stderr_contains(x!("rustc" => "cfg" of "docsrs,test")) .run(); } @@ -284,8 +284,8 @@ fn features_doctest() { p.cargo("test -v --doc") .with_stderr_contains(x!("rustc" => "cfg" of "feature" with "default" "f_a" "f_b")) .with_stderr_contains(x!("rustdoc" => "cfg" of "feature" with "default" "f_a" "f_b")) - .with_stderr_contains(x!("rustc" => "cfg" of "docsrs")) - .with_stderr_contains(x!("rustdoc" => "cfg" of "docsrs")) + .with_stderr_contains(x!("rustc" => "cfg" of "docsrs,test")) + .with_stderr_contains(x!("rustdoc" => "cfg" of "docsrs,test")) .run(); } @@ -298,7 +298,7 @@ fn well_known_names_values_test() { p.cargo("test -v") .with_stderr_contains(x!("rustc" => "cfg" of "feature" with)) - .with_stderr_contains(x!("rustc" => "cfg" of "docsrs")) + .with_stderr_contains(x!("rustc" => "cfg" of "docsrs,test")) .run(); } @@ -312,8 +312,8 @@ fn well_known_names_values_doctest() { p.cargo("test -v --doc") .with_stderr_contains(x!("rustc" => "cfg" of "feature" with)) .with_stderr_contains(x!("rustdoc" => "cfg" of "feature" with)) - .with_stderr_contains(x!("rustc" => "cfg" of "docsrs")) - .with_stderr_contains(x!("rustdoc" => "cfg" of "docsrs")) + .with_stderr_contains(x!("rustc" => "cfg" of "docsrs,test")) + .with_stderr_contains(x!("rustdoc" => "cfg" of "docsrs,test")) .run(); } @@ -339,7 +339,7 @@ fn features_doc() { p.cargo("doc -v") .with_stderr_contains(x!("rustdoc" => "cfg" of "feature" with "default" "f_a" "f_b")) - .with_stderr_contains(x!("rustdoc" => "cfg" of "docsrs")) + .with_stderr_contains(x!("rustdoc" => "cfg" of "docsrs,test")) .run(); } @@ -366,7 +366,7 @@ fn build_script_feedback() { p.cargo("check -v") .with_stderr_contains(x!("rustc" => "cfg" of "foo")) - .with_stderr_contains(x!("rustc" => "cfg" of "docsrs")) + .with_stderr_contains(x!("rustc" => "cfg" of "docsrs,test")) .run(); } @@ -442,7 +442,7 @@ fn build_script_override() { p.cargo("check -v") .with_stderr_contains(x!("rustc" => "cfg" of "foo")) .with_stderr_contains(x!("rustc" => "cfg" of "feature" with)) - .with_stderr_contains(x!("rustc" => "cfg" of "docsrs")) + .with_stderr_contains(x!("rustc" => "cfg" of "docsrs,test")) .run(); } @@ -877,7 +877,7 @@ fn config_features_and_build_script() { .with_stderr_contains(x!("rustc" => "cfg" of "foo")) // from build.rs .with_stderr_contains(x!("rustc" => "cfg" of "bar")) // from config .with_stderr_contains(x!("rustc" => "cfg" of "feature" with "json" "serde")) // features - .with_stderr_contains(x!("rustc" => "cfg" of "docsrs")) // Cargo well known + .with_stderr_contains(x!("rustc" => "cfg" of "docsrs,test")) // Cargo well known .run(); }