Skip to content

Commit 2f1939a

Browse files
Link to the corresponding channel in the help popover
1 parent 2f3bed0 commit 2f1939a

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

src/librustdoc/clean/utils.rs

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use rustc_middle::ty::{self, TyCtxt};
2121
use rustc_span::symbol::{kw, sym, Symbol};
2222
use std::fmt::Write as _;
2323
use std::mem;
24+
use std::sync::LazyLock as Lazy;
2425
use thin_vec::{thin_vec, ThinVec};
2526

2627
#[cfg(test)]
@@ -582,6 +583,8 @@ pub(crate) fn has_doc_flag(tcx: TyCtxt<'_>, did: DefId, flag: Symbol) -> bool {
582583
///
583584
/// Set by `bootstrap::Builder::doc_rust_lang_org_channel` in order to keep tests passing on beta/stable.
584585
pub(crate) const DOC_RUST_LANG_ORG_CHANNEL: &str = env!("DOC_RUST_LANG_ORG_CHANNEL");
586+
pub(crate) static DOC_CHANNEL: Lazy<&'static str> =
587+
Lazy::new(|| DOC_RUST_LANG_ORG_CHANNEL.rsplit("/").filter(|c| !c.is_empty()).next().unwrap());
585588

586589
/// Render a sequence of macro arms in a format suitable for displaying to the user
587590
/// as part of an item declaration.

src/librustdoc/html/layout.rs

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ struct PageLayout<'a> {
5555
sidebar: String,
5656
content: String,
5757
krate_with_trailing_slash: String,
58+
rust_channel: &'static str,
5859
pub(crate) rustdoc_version: &'a str,
5960
}
6061

@@ -82,6 +83,7 @@ pub(crate) fn render<T: Print, S: Print>(
8283
sidebar,
8384
content,
8485
krate_with_trailing_slash,
86+
rust_channel: *crate::clean::utils::DOC_CHANNEL,
8587
rustdoc_version,
8688
}
8789
.render()

src/librustdoc/html/static/js/main.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -1050,9 +1050,10 @@ function preLoadCss(cssUrl) {
10501050

10511051
function buildHelpMenu() {
10521052
const book_info = document.createElement("span");
1053+
const channel = getVar("channel");
10531054
book_info.className = "top";
1054-
book_info.innerHTML = "You can find more information in \
1055-
<a href=\"https://doc.rust-lang.org/rustdoc/\">the rustdoc book</a>.";
1055+
book_info.innerHTML = `You can find more information in \
1056+
<a href="https://doc.rust-lang.org/${channel}/rustdoc/">the rustdoc book</a>.`;
10561057

10571058
const shortcuts = [
10581059
["?", "Show this help dialog"],
@@ -1072,9 +1073,9 @@ function preLoadCss(cssUrl) {
10721073
div_shortcuts.innerHTML = "<h2>Keyboard Shortcuts</h2><dl>" + shortcuts + "</dl></div>";
10731074

10741075
const infos = [
1075-
"For a full list of all search features, take a look <a \
1076-
href='https://doc.rust-lang.org/stable/rustdoc/how-to-read-rustdoc.html\
1077-
#the-search-interface'>here</a>.",
1076+
`For a full list of all search features, take a look <a \
1077+
href="https://doc.rust-lang.org/${channel}/rustdoc/how-to-read-rustdoc.html\
1078+
#the-search-interface">here</a>.`,
10781079
"Prefix searches with a type followed by a colon (e.g., <code>fn:</code>) to \
10791080
restrict the search to a given item kind.",
10801081
"Accepted kinds are: <code>fn</code>, <code>mod</code>, <code>struct</code>, \

src/librustdoc/html/templates/page.html

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
data-themes="{{themes|join(",") }}" {#+ #}
3232
data-resource-suffix="{{page.resource_suffix}}" {#+ #}
3333
data-rustdoc-version="{{rustdoc_version}}" {#+ #}
34+
data-channel="{{rust_channel}}" {#+ #}
3435
data-search-js="{{files.search_js}}" {#+ #}
3536
data-settings-js="{{files.settings_js}}" {#+ #}
3637
data-settings-css="{{files.settings_css}}" {#+ #}

0 commit comments

Comments
 (0)