Skip to content

Commit 3478f83

Browse files
committed
Reuse logic for determining the channel in the rest of rustdoc
This doesn't update main.js because it's included as a fixed string.
1 parent 9866ea0 commit 3478f83

File tree

5 files changed

+29
-22
lines changed

5 files changed

+29
-22
lines changed

src/librustdoc/clean/types.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use rustc_ast::{self as ast, AttrStyle};
1616
use rustc_attr::{ConstStability, Deprecation, Stability, StabilityLevel};
1717
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1818
use rustc_data_structures::thin_vec::ThinVec;
19-
use rustc_feature::UnstableFeatures;
2019
use rustc_hir as hir;
2120
use rustc_hir::def::{CtorKind, Res};
2221
use rustc_hir::def_id::{CrateNum, DefId, DefIndex};
@@ -228,14 +227,9 @@ impl Item {
228227
"../".repeat(depth)
229228
}
230229
Some(&(_, _, ExternalLocation::Remote(ref s))) => s.to_string(),
231-
Some(&(_, _, ExternalLocation::Unknown)) | None => String::from(
232-
// NOTE: intentionally doesn't pass crate name to avoid having
233-
// different primitive links between crates
234-
if UnstableFeatures::from_environment(None).is_nightly_build() {
235-
"https://doc.rust-lang.org/nightly"
236-
} else {
237-
"https://doc.rust-lang.org"
238-
},
230+
Some(&(_, _, ExternalLocation::Unknown)) | None => format!(
231+
"https://doc.rust-lang.org/{}",
232+
crate::doc_rust_lang_org_channel(),
239233
),
240234
};
241235
// This is a primitive so the url is done "by hand".

src/librustdoc/clean/utils.rs

+11
Original file line numberDiff line numberDiff line change
@@ -521,3 +521,14 @@ crate fn has_doc_flag(attrs: ty::Attributes<'_>, flag: Symbol) -> bool {
521521
&& attr.meta_item_list().map_or(false, |l| rustc_attr::list_contains_name(&l, flag))
522522
})
523523
}
524+
525+
/// Return a channel suitable for using in a `doc.rust-lang.org/{channel}` format string.
526+
crate fn doc_rust_lang_org_channel() -> &'static str {
527+
match env!("CFG_RELEASE_CHANNEL") {
528+
"stable" => env!("CFG_RELEASE_NUM"),
529+
"beta" => "beta",
530+
"nightly" | "dev" => "nightly",
531+
// custom build of rustdoc maybe? link to the stable docs just in case
532+
_ => "",
533+
}
534+
}

src/librustdoc/core.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -498,15 +498,18 @@ crate fn run_global_ctxt(
498498
let mut krate = tcx.sess.time("clean_crate", || clean::krate(&mut ctxt));
499499

500500
if krate.module.doc_value().map(|d| d.is_empty()).unwrap_or(true) {
501-
let help = "The following guide may be of use:\n\
502-
https://doc.rust-lang.org/nightly/rustdoc/how-to-write-documentation.html";
501+
let help = format!(
502+
"The following guide may be of use:\n\
503+
https://doc.rust-lang.org/{}/rustdoc/how-to-write-documentation.html",
504+
crate::doc_rust_lang_org_channel(),
505+
);
503506
tcx.struct_lint_node(
504507
crate::lint::MISSING_CRATE_LEVEL_DOCS,
505508
DocContext::as_local_hir_id(tcx, krate.module.def_id).unwrap(),
506509
|lint| {
507510
let mut diag =
508511
lint.build("no documentation found for this crate's top-level module");
509-
diag.help(help);
512+
diag.help(&help);
510513
diag.emit();
511514
},
512515
);

src/librustdoc/lib.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ use rustc_session::config::{make_crate_type_option, ErrorOutputType, RustcOptGro
8282
use rustc_session::getopts;
8383
use rustc_session::{early_error, early_warn};
8484

85+
use crate::clean::utils::doc_rust_lang_org_channel;
86+
8587
/// A macro to create a FxHashMap.
8688
///
8789
/// Example:
@@ -597,7 +599,10 @@ fn usage(argv0: &str) {
597599
}
598600
println!("{}", options.usage(&format!("{} [options] <input>", argv0)));
599601
println!(" @path Read newline separated options from `path`\n");
600-
println!("More information available at https://doc.rust-lang.org/rustdoc/what-is-rustdoc.html")
602+
println!(
603+
"More information available at https://doc.rust-lang.org/{}/rustdoc/what-is-rustdoc.html",
604+
doc_rust_lang_org_channel()
605+
);
601606
}
602607

603608
/// A result type used by several functions under `main()`.

src/librustdoc/passes/collect_intra_doc_links.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -1925,16 +1925,10 @@ fn disambiguator_error(
19251925
) {
19261926
diag_info.link_range = disambiguator_range;
19271927
report_diagnostic(cx.tcx, BROKEN_INTRA_DOC_LINKS, msg, &diag_info, |diag, _sp| {
1928-
let channel = match env!("CFG_RELEASE_CHANNEL") {
1929-
"stable" => env!("CFG_RELEASE_NUM"),
1930-
"beta" => "beta",
1931-
"nightly" | "dev" => "nightly",
1932-
// custom build of rustdoc maybe? link to the stable docs just in case
1933-
_ => "",
1934-
};
19351928
let msg = format!(
1936-
"see https://doc.rust-lang.org/{}/rustdoc/linking-to-items-by-name.html#namespaces-and-disambiguators for more info about disambiguators",
1937-
channel,
1929+
"see https://doc.rust-lang.org/{}/rustdoc/linking-to-items-by-name.html#namespaces-and-disambiguators \
1930+
for more info about disambiguators",
1931+
crate::doc_rust_lang_org_channel(),
19381932
);
19391933
diag.note(&msg);
19401934
});

0 commit comments

Comments
 (0)