Skip to content

Commit

Permalink
Auto merge of #13383 - Urgau:check-cfg-docsrs, r=epage
Browse files Browse the repository at this point in the history
Add `docsrs` cfg as a well known `--check-cfg`

Now that rust-lang/docs.rs#2390 has been merged we can add the `docsrs` cfg in Cargo well known --check-cfg "list". The `docsrs` cfg used by at least [3k project on GitHub](https://github.com/search?q=lang%3Atoml+%2Frustdoc-args+%3D+%5C%5B%22--cfg%22%2C+%22docsrs%22%5C%5D%2F+NOT+is%3Afork&type=code&repo=&langOverride=&start_value=1) alone; including the cfg will help reduce the impact of enabling by default this feature.

> 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.

This is part of the last remaining bits of the `--check-cfg` feature.

r? `@epage`
  • Loading branch information
bors committed Feb 1, 2024
2 parents b1bd44d + dfc40a0 commit a4fe27a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1296,9 +1296,16 @@ fn check_cfg_args(cx: &Context<'_, '_>, unit: &Unit) -> Vec<OsString> {
}
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 {
Expand Down
16 changes: 16 additions & 0 deletions tests/testsuite/check_cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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();
}

Expand All @@ -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();
}

Expand All @@ -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();
}

Expand All @@ -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();
}

Expand All @@ -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();
}

Expand All @@ -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();
}

Expand All @@ -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();
}

Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}

Expand Down

0 comments on commit a4fe27a

Please sign in to comment.