Skip to content

Commit 7411a9e

Browse files
committed
rustdoc: link to stable/beta docs consistently in documentation
## User-facing changes - Intra-doc links to primitives that currently go to rust-lang.org/nightly/std/primitive.x.html will start going to channel that rustdoc was built with. Nightly will continue going to /nightly; Beta will link to /beta; stable compilers will link to /1.52.1 (or whatever version they were built as). - Cross-crate links from std to core currently go to /nightly unconditionally. They will start going to /1.52.0 on stable channels (but remain the same on nightly channels). - Intra-crate links from std to std (or core to core) currently go to the same URL they are hosted at; they will continue to do so. Notably, this is different from everything else because it can preserve the distinction between /stable and /1.52.0 by using relative links. Note that "links" includes both intra-doc links and rustdoc's own automatically generated hyperlinks. ## Implementation changes - Update the testsuite to allow linking to /beta and /1.52.1 in docs - Use an html_root_url for the standard library that's dependent on the channel This avoids linking to nightly docs on stable. - Update rustdoc to use channel-dependent links for primitives from an unknown crate - Set DOC_RUST_LANG_ORG_CHANNEL from bootstrap to ensure it's in sync - Include doc.rust-lang.org in the channel
1 parent c4c2ab5 commit 7411a9e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+139
-120
lines changed

library/alloc/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
#![allow(unused_attributes)]
6060
#![stable(feature = "alloc", since = "1.36.0")]
6161
#![doc(
62-
html_root_url = "https://doc.rust-lang.org/nightly/",
6362
html_playground_url = "https://play.rust-lang.org/",
6463
issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/",
6564
test(no_crate_inject, attr(allow(unused_variables), deny(warnings)))

library/core/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
#![cfg(not(test))]
5252
#![stable(feature = "core", since = "1.6.0")]
5353
#![doc(
54-
html_root_url = "https://doc.rust-lang.org/nightly/",
5554
html_playground_url = "https://play.rust-lang.org/",
5655
issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/",
5756
test(no_crate_inject, attr(deny(warnings))),

library/panic_abort/src/lib.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
66
#![no_std]
77
#![unstable(feature = "panic_abort", issue = "32837")]
8-
#![doc(
9-
html_root_url = "https://doc.rust-lang.org/nightly/",
10-
issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/"
11-
)]
8+
#![doc(issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/")]
129
#![panic_runtime]
1310
#![allow(unused_features)]
1411
#![feature(core_intrinsics)]

library/panic_unwind/src/lib.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@
1313
1414
#![no_std]
1515
#![unstable(feature = "panic_unwind", issue = "32837")]
16-
#![doc(
17-
html_root_url = "https://doc.rust-lang.org/nightly/",
18-
issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/"
19-
)]
16+
#![doc(issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/")]
2017
#![feature(core_intrinsics)]
2118
#![feature(lang_items)]
2219
#![feature(nll)]

library/proc_macro/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#![stable(feature = "proc_macro_lib", since = "1.15.0")]
1313
#![deny(missing_docs)]
1414
#![doc(
15-
html_root_url = "https://doc.rust-lang.org/nightly/",
1615
html_playground_url = "https://play.rust-lang.org/",
1716
issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/",
1817
test(no_crate_inject, attr(deny(warnings))),

library/std/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@
190190
#![cfg_attr(not(feature = "restricted-std"), stable(feature = "rust1", since = "1.0.0"))]
191191
#![cfg_attr(feature = "restricted-std", unstable(feature = "restricted_std", issue = "none"))]
192192
#![doc(
193-
html_root_url = "https://doc.rust-lang.org/nightly/",
194193
html_playground_url = "https://play.rust-lang.org/",
195194
issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/",
196195
test(no_crate_inject, attr(deny(warnings))),

library/term/src/lib.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,7 @@
3030
//! [win]: https://docs.microsoft.com/en-us/windows/console/character-mode-applications
3131
//! [ti]: https://en.wikipedia.org/wiki/Terminfo
3232
33-
#![doc(
34-
html_root_url = "https://doc.rust-lang.org/nightly/",
35-
html_playground_url = "https://play.rust-lang.org/",
36-
test(attr(deny(warnings)))
37-
)]
33+
#![doc(html_playground_url = "https://play.rust-lang.org/", test(attr(deny(warnings))))]
3834
#![deny(missing_docs)]
3935
#![cfg_attr(windows, feature(libc))]
4036

library/test/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
#![crate_name = "test"]
2121
#![unstable(feature = "test", issue = "50297")]
22-
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/", test(attr(deny(warnings))))]
22+
#![doc(test(attr(deny(warnings))))]
2323
#![cfg_attr(unix, feature(libc))]
2424
#![feature(rustc_private)]
2525
#![feature(nll)]

src/bootstrap/builder.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,18 @@ impl<'a> Builder<'a> {
574574
self.run_step_descriptions(&Builder::get_step_descriptions(Kind::Doc), paths);
575575
}
576576

577+
/// NOTE: keep this in sync with `rustdoc::clean::utils::doc_rust_lang_org_channel`, or tests will fail on beta/stable.
578+
pub fn doc_rust_lang_org_channel(&self) -> String {
579+
let channel = match &*self.config.channel {
580+
"stable" => &self.version,
581+
"beta" => "beta",
582+
"nightly" | "dev" => "nightly",
583+
// custom build of rustdoc maybe? link to the latest stable docs just in case
584+
_ => "stable",
585+
};
586+
"https://doc.rust-lang.org/".to_owned() + channel
587+
}
588+
577589
fn run_step_descriptions(&self, v: &[StepDescription], paths: &[PathBuf]) {
578590
StepDescription::run(v, self, paths);
579591
}

src/bootstrap/compile.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,11 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, stage: u32, car
326326
if target.contains("riscv") {
327327
cargo.rustflag("-Cforce-unwind-tables=yes");
328328
}
329+
330+
let html_root =
331+
format!("-Zcrate-attr=doc(html_root_url=\"{}/\")", builder.doc_rust_lang_org_channel(),);
332+
cargo.rustflag(&html_root);
333+
cargo.rustdocflag(&html_root);
329334
}
330335

331336
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]

0 commit comments

Comments
 (0)