Skip to content

Commit a4fe27a

Browse files
committed
Auto merge of #13383 - Urgau:check-cfg-docsrs, r=epage
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`
2 parents b1bd44d + dfc40a0 commit a4fe27a

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/cargo/core/compiler/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1296,9 +1296,16 @@ fn check_cfg_args(cx: &Context<'_, '_>, unit: &Unit) -> Vec<OsString> {
12961296
}
12971297
arg_feature.push("))");
12981298

1299+
// We also include the `docsrs` cfg from the docs.rs service. We include it here
1300+
// (in Cargo) instead of rustc, since there is a much closer relationship between
1301+
// Cargo and docs.rs than rustc and docs.rs. In particular, all users of docs.rs use
1302+
// Cargo, but not all users of rustc (like Rust-for-Linux) use docs.rs.
1303+
12991304
vec![
13001305
OsString::from("-Zunstable-options"),
13011306
OsString::from("--check-cfg"),
1307+
OsString::from("cfg(docsrs)"),
1308+
OsString::from("--check-cfg"),
13021309
arg_feature,
13031310
]
13041311
} else {

tests/testsuite/check_cfg.rs

+16
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ fn features() {
5050
p.cargo("check -v -Zcheck-cfg")
5151
.masquerade_as_nightly_cargo(&["check-cfg"])
5252
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with "f_a" "f_b"))
53+
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
5354
.run();
5455
}
5556

@@ -79,6 +80,7 @@ fn features_with_deps() {
7980
p.cargo("check -v -Zcheck-cfg")
8081
.masquerade_as_nightly_cargo(&["check-cfg"])
8182
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with "f_a" "f_b"))
83+
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
8284
.run();
8385
}
8486

@@ -109,6 +111,7 @@ fn features_with_opt_deps() {
109111
p.cargo("check -v -Zcheck-cfg")
110112
.masquerade_as_nightly_cargo(&["check-cfg"])
111113
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with "bar" "default" "f_a" "f_b"))
114+
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
112115
.run();
113116
}
114117

@@ -138,6 +141,7 @@ fn features_with_namespaced_features() {
138141
p.cargo("check -v -Zcheck-cfg")
139142
.masquerade_as_nightly_cargo(&["check-cfg"])
140143
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with "f_a" "f_b"))
144+
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
141145
.run();
142146
}
143147

@@ -222,6 +226,7 @@ fn well_known_names_values() {
222226
p.cargo("check -v -Zcheck-cfg")
223227
.masquerade_as_nightly_cargo(&["check-cfg"])
224228
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with))
229+
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
225230
.run();
226231
}
227232

@@ -246,6 +251,7 @@ fn features_test() {
246251
p.cargo("test -v -Zcheck-cfg")
247252
.masquerade_as_nightly_cargo(&["check-cfg"])
248253
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with "f_a" "f_b"))
254+
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
249255
.run();
250256
}
251257

@@ -272,6 +278,8 @@ fn features_doctest() {
272278
.masquerade_as_nightly_cargo(&["check-cfg"])
273279
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with "default" "f_a" "f_b"))
274280
.with_stderr_contains(x!("rustdoc" => "cfg" of "feature" with "default" "f_a" "f_b"))
281+
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
282+
.with_stderr_contains(x!("rustdoc" => "cfg" of "docsrs"))
275283
.run();
276284
}
277285

@@ -285,6 +293,7 @@ fn well_known_names_values_test() {
285293
p.cargo("test -v -Zcheck-cfg")
286294
.masquerade_as_nightly_cargo(&["check-cfg"])
287295
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with))
296+
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
288297
.run();
289298
}
290299

@@ -299,6 +308,8 @@ fn well_known_names_values_doctest() {
299308
.masquerade_as_nightly_cargo(&["check-cfg"])
300309
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with))
301310
.with_stderr_contains(x!("rustdoc" => "cfg" of "feature" with))
311+
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
312+
.with_stderr_contains(x!("rustdoc" => "cfg" of "docsrs"))
302313
.run();
303314
}
304315

@@ -324,6 +335,7 @@ fn features_doc() {
324335
p.cargo("doc -v -Zcheck-cfg")
325336
.masquerade_as_nightly_cargo(&["check-cfg"])
326337
.with_stderr_contains(x!("rustdoc" => "cfg" of "feature" with "default" "f_a" "f_b"))
338+
.with_stderr_contains(x!("rustdoc" => "cfg" of "docsrs"))
327339
.run();
328340
}
329341

@@ -350,6 +362,7 @@ fn build_script_feedback() {
350362
p.cargo("check -v -Zcheck-cfg")
351363
.masquerade_as_nightly_cargo(&["check-cfg"])
352364
.with_stderr_contains(x!("rustc" => "cfg" of "foo"))
365+
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
353366
.run();
354367
}
355368

@@ -423,6 +436,8 @@ fn build_script_override() {
423436

424437
p.cargo("check -v -Zcheck-cfg")
425438
.with_stderr_contains(x!("rustc" => "cfg" of "foo"))
439+
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with))
440+
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
426441
.masquerade_as_nightly_cargo(&["check-cfg"])
427442
.run();
428443
}
@@ -573,6 +588,7 @@ fn config_valid() {
573588
p.cargo("check -v")
574589
.masquerade_as_nightly_cargo(&["check-cfg"])
575590
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with "f_a" "f_b"))
591+
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
576592
.run();
577593
}
578594

0 commit comments

Comments
 (0)