Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9c17646

Browse files
authoredDec 19, 2024
Add the test cfg as a well known cfg before of compiler change (#14963)
### What does this PR try to resolve? This PR adds the `test` cfg as a well known Cargo cfg as rust-lang/compiler-team#785 is now in FCP and before the compiler change. ### How should we test and review this PR? Look at the new argument passed and the test changes. ### Additional information Detailed motivation at rust-lang/compiler-team#785, but summary `test` is a weird well known cfg for `rustc` as it's mostly a convention and build system like Cargo may to set it conditionally (`lib.test = false` for Cargo, not done in this PR). Pre-require to rust-lang/rust#131729. r? @epage
2 parents 59b2ddd + 5720eb7 commit 9c17646

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed
 

‎src/cargo/core/compiler/mod.rs

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

1394-
// We also include the `docsrs` cfg from the docs.rs service. We include it here
1395-
// (in Cargo) instead of rustc, since there is a much closer relationship between
1396-
// Cargo and docs.rs than rustc and docs.rs. In particular, all users of docs.rs use
1397-
// Cargo, but not all users of rustc (like Rust-for-Linux) use docs.rs.
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.
1397+
//
1398+
// We include `docsrs` here (in Cargo) instead of rustc, since there is a much closer
1399+
// relationship between Cargo and docs.rs than rustc and docs.rs. In particular, all
1400+
// users of docs.rs use Cargo, but not all users of rustc (like Rust-for-Linux) use docs.rs.
13981401

13991402
vec![
14001403
OsString::from("--check-cfg"),
1401-
OsString::from("cfg(docsrs)"),
1404+
OsString::from("cfg(docsrs,test)"),
14021405
OsString::from("--check-cfg"),
14031406
arg_feature,
14041407
]

‎tests/testsuite/check_cfg.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ fn features() {
5151

5252
p.cargo("check -v")
5353
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with "f_a" "f_b"))
54-
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
54+
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs,test"))
5555
.run();
5656
}
5757

@@ -81,7 +81,7 @@ fn features_with_deps() {
8181

8282
p.cargo("check -v")
8383
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with "f_a" "f_b"))
84-
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
84+
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs,test"))
8585
.run();
8686
}
8787

@@ -112,7 +112,7 @@ fn features_with_opt_deps() {
112112

113113
p.cargo("check -v")
114114
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with "bar" "default" "f_a" "f_b"))
115-
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
115+
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs,test"))
116116
.run();
117117
}
118118

@@ -142,7 +142,7 @@ fn features_with_namespaced_features() {
142142

143143
p.cargo("check -v")
144144
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with "f_a" "f_b"))
145-
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
145+
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs,test"))
146146
.run();
147147
}
148148

@@ -232,7 +232,7 @@ fn well_known_names_values() {
232232

233233
p.cargo("check -v")
234234
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with))
235-
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
235+
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs,test"))
236236
.run();
237237
}
238238

@@ -257,7 +257,7 @@ fn features_test() {
257257

258258
p.cargo("test -v")
259259
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with "f_a" "f_b"))
260-
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
260+
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs,test"))
261261
.run();
262262
}
263263

@@ -284,8 +284,8 @@ fn features_doctest() {
284284
p.cargo("test -v --doc")
285285
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with "default" "f_a" "f_b"))
286286
.with_stderr_contains(x!("rustdoc" => "cfg" of "feature" with "default" "f_a" "f_b"))
287-
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
288-
.with_stderr_contains(x!("rustdoc" => "cfg" of "docsrs"))
287+
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs,test"))
288+
.with_stderr_contains(x!("rustdoc" => "cfg" of "docsrs,test"))
289289
.run();
290290
}
291291

@@ -298,7 +298,7 @@ fn well_known_names_values_test() {
298298

299299
p.cargo("test -v")
300300
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with))
301-
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
301+
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs,test"))
302302
.run();
303303
}
304304

@@ -312,8 +312,8 @@ fn well_known_names_values_doctest() {
312312
p.cargo("test -v --doc")
313313
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with))
314314
.with_stderr_contains(x!("rustdoc" => "cfg" of "feature" with))
315-
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
316-
.with_stderr_contains(x!("rustdoc" => "cfg" of "docsrs"))
315+
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs,test"))
316+
.with_stderr_contains(x!("rustdoc" => "cfg" of "docsrs,test"))
317317
.run();
318318
}
319319

@@ -339,7 +339,7 @@ fn features_doc() {
339339

340340
p.cargo("doc -v")
341341
.with_stderr_contains(x!("rustdoc" => "cfg" of "feature" with "default" "f_a" "f_b"))
342-
.with_stderr_contains(x!("rustdoc" => "cfg" of "docsrs"))
342+
.with_stderr_contains(x!("rustdoc" => "cfg" of "docsrs,test"))
343343
.run();
344344
}
345345

@@ -366,7 +366,7 @@ fn build_script_feedback() {
366366

367367
p.cargo("check -v")
368368
.with_stderr_contains(x!("rustc" => "cfg" of "foo"))
369-
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
369+
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs,test"))
370370
.run();
371371
}
372372

@@ -442,7 +442,7 @@ fn build_script_override() {
442442
p.cargo("check -v")
443443
.with_stderr_contains(x!("rustc" => "cfg" of "foo"))
444444
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with))
445-
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
445+
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs,test"))
446446
.run();
447447
}
448448

@@ -877,7 +877,7 @@ fn config_features_and_build_script() {
877877
.with_stderr_contains(x!("rustc" => "cfg" of "foo")) // from build.rs
878878
.with_stderr_contains(x!("rustc" => "cfg" of "bar")) // from config
879879
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with "json" "serde")) // features
880-
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs")) // Cargo well known
880+
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs,test")) // Cargo well known
881881
.run();
882882
}
883883

0 commit comments

Comments
 (0)
Failed to load comments.