From dfc40a0ca6d529c7f2e06898972afab1728c6a55 Mon Sep 17 00:00:00 2001 From: Urgau Date: Thu, 25 Jan 2024 14:54:09 +0100 Subject: [PATCH] Add docsrs cfg as a well known --check-cfg --- src/cargo/core/compiler/mod.rs | 7 +++++++ tests/testsuite/check_cfg.rs | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/cargo/core/compiler/mod.rs b/src/cargo/core/compiler/mod.rs index 14e4bde4b11..352e48bd756 100644 --- a/src/cargo/core/compiler/mod.rs +++ b/src/cargo/core/compiler/mod.rs @@ -1296,9 +1296,16 @@ fn check_cfg_args(cx: &Context<'_, '_>, 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. + vec![ OsString::from("-Zunstable-options"), OsString::from("--check-cfg"), + OsString::from("cfg(docsrs)"), + OsString::from("--check-cfg"), arg_feature, ] } else { diff --git a/tests/testsuite/check_cfg.rs b/tests/testsuite/check_cfg.rs index 5f34774094e..b48d4f6d7d6 100644 --- a/tests/testsuite/check_cfg.rs +++ b/tests/testsuite/check_cfg.rs @@ -50,6 +50,7 @@ fn features() { p.cargo("check -v -Zcheck-cfg") .masquerade_as_nightly_cargo(&["check-cfg"]) .with_stderr_contains(x!("rustc" => "cfg" of "feature" with "f_a" "f_b")) + .with_stderr_contains(x!("rustc" => "cfg" of "docsrs")) .run(); } @@ -79,6 +80,7 @@ fn features_with_deps() { p.cargo("check -v -Zcheck-cfg") .masquerade_as_nightly_cargo(&["check-cfg"]) .with_stderr_contains(x!("rustc" => "cfg" of "feature" with "f_a" "f_b")) + .with_stderr_contains(x!("rustc" => "cfg" of "docsrs")) .run(); } @@ -109,6 +111,7 @@ fn features_with_opt_deps() { p.cargo("check -v -Zcheck-cfg") .masquerade_as_nightly_cargo(&["check-cfg"]) .with_stderr_contains(x!("rustc" => "cfg" of "feature" with "bar" "default" "f_a" "f_b")) + .with_stderr_contains(x!("rustc" => "cfg" of "docsrs")) .run(); } @@ -138,6 +141,7 @@ fn features_with_namespaced_features() { p.cargo("check -v -Zcheck-cfg") .masquerade_as_nightly_cargo(&["check-cfg"]) .with_stderr_contains(x!("rustc" => "cfg" of "feature" with "f_a" "f_b")) + .with_stderr_contains(x!("rustc" => "cfg" of "docsrs")) .run(); } @@ -222,6 +226,7 @@ fn well_known_names_values() { p.cargo("check -v -Zcheck-cfg") .masquerade_as_nightly_cargo(&["check-cfg"]) .with_stderr_contains(x!("rustc" => "cfg" of "feature" with)) + .with_stderr_contains(x!("rustc" => "cfg" of "docsrs")) .run(); } @@ -246,6 +251,7 @@ fn features_test() { p.cargo("test -v -Zcheck-cfg") .masquerade_as_nightly_cargo(&["check-cfg"]) .with_stderr_contains(x!("rustc" => "cfg" of "feature" with "f_a" "f_b")) + .with_stderr_contains(x!("rustc" => "cfg" of "docsrs")) .run(); } @@ -272,6 +278,8 @@ fn features_doctest() { .masquerade_as_nightly_cargo(&["check-cfg"]) .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")) .run(); } @@ -285,6 +293,7 @@ fn well_known_names_values_test() { p.cargo("test -v -Zcheck-cfg") .masquerade_as_nightly_cargo(&["check-cfg"]) .with_stderr_contains(x!("rustc" => "cfg" of "feature" with)) + .with_stderr_contains(x!("rustc" => "cfg" of "docsrs")) .run(); } @@ -299,6 +308,8 @@ fn well_known_names_values_doctest() { .masquerade_as_nightly_cargo(&["check-cfg"]) .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")) .run(); } @@ -324,6 +335,7 @@ fn features_doc() { p.cargo("doc -v -Zcheck-cfg") .masquerade_as_nightly_cargo(&["check-cfg"]) .with_stderr_contains(x!("rustdoc" => "cfg" of "feature" with "default" "f_a" "f_b")) + .with_stderr_contains(x!("rustdoc" => "cfg" of "docsrs")) .run(); } @@ -350,6 +362,7 @@ fn build_script_feedback() { p.cargo("check -v -Zcheck-cfg") .masquerade_as_nightly_cargo(&["check-cfg"]) .with_stderr_contains(x!("rustc" => "cfg" of "foo")) + .with_stderr_contains(x!("rustc" => "cfg" of "docsrs")) .run(); } @@ -423,6 +436,8 @@ fn build_script_override() { p.cargo("check -v -Zcheck-cfg") .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")) .masquerade_as_nightly_cargo(&["check-cfg"]) .run(); } @@ -573,6 +588,7 @@ fn config_valid() { p.cargo("check -v") .masquerade_as_nightly_cargo(&["check-cfg"]) .with_stderr_contains(x!("rustc" => "cfg" of "feature" with "f_a" "f_b")) + .with_stderr_contains(x!("rustc" => "cfg" of "docsrs")) .run(); }