Skip to content

Commit e25f9fc

Browse files
authored
Rollup merge of rust-lang#134807 - poliorcetics:ab/push-skpynvsmwkll, r=camelid
fix(rustdoc): always use a channel when linking to doc.rust-lang.org Closes rust-lang#131971 I manually checked the resulting links One issue is that this will create `nightly/...` links in places that formerly linked to stable, is that ok ? (the `slice` and `array` links in the search help notably)
2 parents d96a693 + a063cf5 commit e25f9fc

File tree

14 files changed

+31
-30
lines changed

14 files changed

+31
-30
lines changed

src/librustdoc/clean/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1934,7 +1934,7 @@ fn can_elide_trait_object_lifetime_bound<'tcx>(
19341934
preds: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
19351935
tcx: TyCtxt<'tcx>,
19361936
) -> bool {
1937-
// Below we quote extracts from https://doc.rust-lang.org/reference/lifetime-elision.html#default-trait-object-lifetimes
1937+
// Below we quote extracts from https://doc.rust-lang.org/stable/reference/lifetime-elision.html#default-trait-object-lifetimes
19381938

19391939
// > If the trait object is used as a type argument of a generic type then the containing type is
19401940
// > first used to try to infer a bound.

src/librustdoc/clean/utils.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -588,9 +588,9 @@ pub(crate) fn attrs_have_doc_flag<'a>(
588588
/// so that the channel is consistent.
589589
///
590590
/// Set by `bootstrap::Builder::doc_rust_lang_org_channel` in order to keep tests passing on beta/stable.
591-
pub(crate) const DOC_RUST_LANG_ORG_CHANNEL: &str = env!("DOC_RUST_LANG_ORG_CHANNEL");
592-
pub(crate) static DOC_CHANNEL: Lazy<&'static str> =
593-
Lazy::new(|| DOC_RUST_LANG_ORG_CHANNEL.rsplit('/').find(|c| !c.is_empty()).unwrap());
591+
pub(crate) const DOC_RUST_LANG_ORG_VERSION: &str = env!("DOC_RUST_LANG_ORG_CHANNEL");
592+
pub(crate) static RUSTDOC_VERSION: Lazy<&'static str> =
593+
Lazy::new(|| DOC_RUST_LANG_ORG_VERSION.rsplit('/').find(|c| !c.is_empty()).unwrap());
594594

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

src/librustdoc/core.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ pub(crate) fn run_global_ctxt(
387387
let help = format!(
388388
"The following guide may be of use:\n\
389389
{}/rustdoc/how-to-write-documentation.html",
390-
crate::DOC_RUST_LANG_ORG_CHANNEL
390+
crate::DOC_RUST_LANG_ORG_VERSION
391391
);
392392
tcx.node_lint(
393393
crate::lint::MISSING_CRATE_LEVEL_DOCS,

src/librustdoc/html/layout.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ pub(crate) fn render<T: Print, S: Print>(
112112
display_krate_with_trailing_slash,
113113
display_krate_version_number,
114114
display_krate_version_extra,
115-
rust_channel: *crate::clean::utils::DOC_CHANNEL,
115+
rust_channel: *crate::clean::utils::RUSTDOC_VERSION,
116116
rustdoc_version,
117117
}
118118
.render()

src/librustdoc/html/render/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use crate::html::render::write_shared::write_shared;
3232
use crate::html::url_parts_builder::UrlPartsBuilder;
3333
use crate::html::{layout, sources, static_files};
3434
use crate::scrape_examples::AllCallLocations;
35-
use crate::try_err;
35+
use crate::{DOC_RUST_LANG_ORG_VERSION, try_err};
3636

3737
/// Major driving force in all rustdoc rendering. This contains information
3838
/// about where in the tree-like hierarchy rendering is occurring and controls
@@ -730,7 +730,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
730730
<noscript>\
731731
<section>\
732732
<p>You need to enable JavaScript to use keyboard commands or search.</p>\
733-
<p>For more information, browse the <a href=\"https://doc.rust-lang.org/rustdoc/\">rustdoc handbook</a>.</p>\
733+
<p>For more information, browse the <a href=\"{DOC_RUST_LANG_ORG_VERSION}/rustdoc/\">rustdoc handbook</a>.</p>\
734734
</section>\
735735
</noscript>",
736736
)

src/librustdoc/html/render/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ use crate::html::markdown::{
7979
use crate::html::static_files::SCRAPE_EXAMPLES_HELP_MD;
8080
use crate::html::{highlight, sources};
8181
use crate::scrape_examples::{CallData, CallLocation};
82-
use crate::{DOC_RUST_LANG_ORG_CHANNEL, try_none};
82+
use crate::{DOC_RUST_LANG_ORG_VERSION, try_none};
8383

8484
pub(crate) fn ensure_trailing_slash(v: &str) -> impl fmt::Display + '_ {
8585
fmt::from_fn(move |f| {
@@ -480,7 +480,7 @@ fn scrape_examples_help(shared: &SharedContext<'_>) -> String {
480480
content.push_str(&format!(
481481
"## More information\n\n\
482482
If you want more information about this feature, please read the [corresponding chapter in \
483-
the Rustdoc book]({DOC_RUST_LANG_ORG_CHANNEL}/rustdoc/scraped-examples.html)."
483+
the Rustdoc book]({DOC_RUST_LANG_ORG_VERSION}/rustdoc/scraped-examples.html)."
484484
));
485485

486486
let mut ids = IdMap::default();

src/librustdoc/html/render/print_item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
924924
<a href=\"{base}/reference/items/traits.html#dyn-compatibility\">dyn compatible</a>.</p>\
925925
<p><i>In older versions of Rust, dyn compatibility was called \"object safety\", \
926926
so this trait is not object safe.</i></p></div>",
927-
base = crate::clean::utils::DOC_RUST_LANG_ORG_CHANNEL
927+
base = crate::clean::utils::DOC_RUST_LANG_ORG_VERSION
928928
),
929929
);
930930
}

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

+8-8
Original file line numberDiff line numberDiff line change
@@ -1534,10 +1534,10 @@ function preLoadCss(cssUrl) {
15341534

15351535
function buildHelpMenu() {
15361536
const book_info = document.createElement("span");
1537-
const channel = getVar("channel");
1537+
const drloChannel = `https://doc.rust-lang.org/${getVar("channel")}`;
15381538
book_info.className = "top";
15391539
book_info.innerHTML = `You can find more information in \
1540-
<a href="https://doc.rust-lang.org/${channel}/rustdoc/">the rustdoc book</a>.`;
1540+
<a href="${drloChannel}/rustdoc/">the rustdoc book</a>.`;
15411541

15421542
const shortcuts = [
15431543
["?", "Show this help dialog"],
@@ -1557,8 +1557,8 @@ function preLoadCss(cssUrl) {
15571557
div_shortcuts.innerHTML = "<h2>Keyboard Shortcuts</h2><dl>" + shortcuts + "</dl></div>";
15581558

15591559
const infos = [
1560-
`For a full list of all search features, take a look <a \
1561-
href="https://doc.rust-lang.org/${channel}/rustdoc/read-documentation/search.html">here</a>.`,
1560+
`For a full list of all search features, take a look \
1561+
<a href="${drloChannel}/rustdoc/read-documentation/search.html">here</a>.`,
15621562
"Prefix searches with a type followed by a colon (e.g., <code>fn:</code>) to \
15631563
restrict the search to a given item kind.",
15641564
"Accepted kinds are: <code>fn</code>, <code>mod</code>, <code>struct</code>, \
@@ -1568,10 +1568,10 @@ href="https://doc.rust-lang.org/${channel}/rustdoc/read-documentation/search.htm
15681568
<code>-&gt; vec</code> or <code>String, enum:Cow -&gt; bool</code>)",
15691569
"You can look for items with an exact name by putting double quotes around \
15701570
your request: <code>\"string\"</code>",
1571-
"Look for functions that accept or return \
1572-
<a href=\"https://doc.rust-lang.org/std/primitive.slice.html\">slices</a> and \
1573-
<a href=\"https://doc.rust-lang.org/std/primitive.array.html\">arrays</a> by writing \
1574-
square brackets (e.g., <code>-&gt; [u8]</code> or <code>[] -&gt; Option</code>)",
1571+
`Look for functions that accept or return \
1572+
<a href="${drloChannel}/std/primitive.slice.html">slices</a> and \
1573+
<a href="${drloChannel}/std/primitive.array.html">arrays</a> by writing square \
1574+
brackets (e.g., <code>-&gt; [u8]</code> or <code>[] -&gt; Option</code>)`,
15751575
"Look for items inside another one by searching for a path: <code>vec::Vec</code>",
15761576
].map(x => "<p>" + x + "</p>").join("");
15771577
const div_infos = document.createElement("div");

src/librustdoc/html/static/js/search.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// ignore-tidy-filelength
2-
/* global addClass, getNakedUrl, getSettingValue */
2+
/* global addClass, getNakedUrl, getSettingValue, getVar */
33
/* global onEachLazy, removeClass, searchState, browserSupportsHistoryApi, exports */
44

55
"use strict";
@@ -4923,17 +4923,18 @@ ${item.displayPath}<span class="${type}">${name}</span>\
49234923
}
49244924
});
49254925
} else if (query.error === null) {
4926+
const dlroChannel = `https://doc.rust-lang.org/${getVar("channel")}`;
49264927
output.className = "search-failed" + extraClass;
49274928
output.innerHTML = "No results :(<br/>" +
49284929
"Try on <a href=\"https://duckduckgo.com/?q=" +
49294930
encodeURIComponent("rust " + query.userQuery) +
49304931
"\">DuckDuckGo</a>?<br/><br/>" +
49314932
"Or try looking in one of these:<ul><li>The <a " +
4932-
"href=\"https://doc.rust-lang.org/reference/index.html\">Rust Reference</a> " +
4933+
`href="${dlroChannel}/reference/index.html">Rust Reference</a> ` +
49334934
" for technical details about the language.</li><li><a " +
4934-
"href=\"https://doc.rust-lang.org/rust-by-example/index.html\">Rust By " +
4935+
`href="${dlroChannel}/rust-by-example/index.html">Rust By ` +
49354936
"Example</a> for expository code examples.</a></li><li>The <a " +
4936-
"href=\"https://doc.rust-lang.org/book/index.html\">Rust Book</a> for " +
4937+
`href="${dlroChannel}/book/index.html">Rust Book</a> for ` +
49374938
"introductions to language features and the language itself.</li><li><a " +
49384939
"href=\"https://docs.rs\">Docs.rs</a> for documentation of crates released on" +
49394940
" <a href=\"https://crates.io/\">crates.io</a>.</li></ul>";

src/librustdoc/html/templates/type_layout.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ <h2 id="layout" class="section-header"> {# #}
1010
unstable</strong> and may even differ between compilations. {#+ #}
1111
The only exception is types with certain <code>repr(...)</code> {#+ #}
1212
attributes. Please see the Rust Reference's {#+ #}
13-
<a href="https://doc.rust-lang.org/reference/type-layout.html">“Type Layout”</a> {#+ #}
13+
<a href="{{ crate::DOC_RUST_LANG_ORG_VERSION }}/reference/type-layout.html">“Type Layout”</a> {#+ #}
1414
chapter for details on type layout guarantees. {# #}
1515
</p> {# #}
1616
</div> {# #}

src/librustdoc/html/templates/type_layout_size.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
{{ size +}} bytes
88
{% endif %}
99
{% if is_uninhabited %}
10-
{# +#} (<a href="https://doc.rust-lang.org/stable/reference/glossary.html#uninhabited">uninhabited</a>)
10+
{# +#} (<a href="{{ crate::DOC_RUST_LANG_ORG_VERSION }}/reference/glossary.html#uninhabited">uninhabited</a>)
1111
{% endif %}
1212
{% endif %}

src/librustdoc/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ use rustc_session::config::{ErrorOutputType, RustcOptGroup, make_crate_type_opti
8282
use rustc_session::{EarlyDiagCtxt, getopts};
8383
use tracing::info;
8484

85-
use crate::clean::utils::DOC_RUST_LANG_ORG_CHANNEL;
85+
use crate::clean::utils::DOC_RUST_LANG_ORG_VERSION;
8686

8787
/// A macro to create a FxHashMap.
8888
///
@@ -709,7 +709,7 @@ fn usage(argv0: &str) {
709709
println!("{}", options.usage(&format!("{argv0} [options] <input>")));
710710
println!(" @path Read newline separated options from `path`\n");
711711
println!(
712-
"More information available at {DOC_RUST_LANG_ORG_CHANNEL}/rustdoc/what-is-rustdoc.html",
712+
"More information available at {DOC_RUST_LANG_ORG_VERSION}/rustdoc/what-is-rustdoc.html",
713713
);
714714
}
715715

src/librustdoc/passes/collect_intra_doc_links.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2168,7 +2168,7 @@ fn disambiguator_error(
21682168
report_diagnostic(cx.tcx, BROKEN_INTRA_DOC_LINKS, msg, &diag_info, |diag, _sp, _link_range| {
21692169
let msg = format!(
21702170
"see {}/rustdoc/write-documentation/linking-to-items-by-name.html#namespaces-and-disambiguators for more info about disambiguators",
2171-
crate::DOC_RUST_LANG_ORG_CHANNEL
2171+
crate::DOC_RUST_LANG_ORG_VERSION
21722172
);
21732173
diag.note(msg);
21742174
});

tests/rustdoc/type-layout.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ pub enum WithNiche {
8686
}
8787

8888
//@ hasraw type_layout/enum.Uninhabited.html 'Size: '
89-
//@ hasraw - '0 bytes (<a href="https://doc.rust-lang.org/stable/reference/glossary.html#uninhabited">uninhabited</a>)'
89+
//@ hasraw - '0 bytes (<a href="{{channel}}/reference/glossary.html#uninhabited">uninhabited</a>)'
9090
pub enum Uninhabited {}
9191

9292
//@ hasraw type_layout/struct.Uninhabited2.html 'Size: '
93-
//@ hasraw - '8 bytes (<a href="https://doc.rust-lang.org/stable/reference/glossary.html#uninhabited">uninhabited</a>)'
93+
//@ hasraw - '8 bytes (<a href="{{channel}}/reference/glossary.html#uninhabited">uninhabited</a>)'
9494
pub struct Uninhabited2(std::convert::Infallible, u64);
9595

9696
pub trait Project { type Assoc; }

0 commit comments

Comments
 (0)