Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the test cfg as a well known cfg before of compiler change #14963

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1391,14 +1391,17 @@ fn check_cfg_args(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.
// 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,
]
Expand Down
30 changes: 15 additions & 15 deletions tests/testsuite/check_cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

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

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

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

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

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

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

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

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

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

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

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

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

Expand Down
Loading