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.
This commit is contained in:
parent
9866ea0ac5
commit
3478f83c0a
5 changed files with 29 additions and 22 deletions
|
@ -16,7 +16,6 @@ use rustc_ast::{self as ast, AttrStyle};
|
||||||
use rustc_attr::{ConstStability, Deprecation, Stability, StabilityLevel};
|
use rustc_attr::{ConstStability, Deprecation, Stability, StabilityLevel};
|
||||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||||
use rustc_data_structures::thin_vec::ThinVec;
|
use rustc_data_structures::thin_vec::ThinVec;
|
||||||
use rustc_feature::UnstableFeatures;
|
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::{CtorKind, Res};
|
use rustc_hir::def::{CtorKind, Res};
|
||||||
use rustc_hir::def_id::{CrateNum, DefId, DefIndex};
|
use rustc_hir::def_id::{CrateNum, DefId, DefIndex};
|
||||||
|
@ -228,14 +227,9 @@ impl Item {
|
||||||
"../".repeat(depth)
|
"../".repeat(depth)
|
||||||
}
|
}
|
||||||
Some(&(_, _, ExternalLocation::Remote(ref s))) => s.to_string(),
|
Some(&(_, _, ExternalLocation::Remote(ref s))) => s.to_string(),
|
||||||
Some(&(_, _, ExternalLocation::Unknown)) | None => String::from(
|
Some(&(_, _, ExternalLocation::Unknown)) | None => format!(
|
||||||
// NOTE: intentionally doesn't pass crate name to avoid having
|
"https://doc.rust-lang.org/{}",
|
||||||
// different primitive links between crates
|
crate::doc_rust_lang_org_channel(),
|
||||||
if UnstableFeatures::from_environment(None).is_nightly_build() {
|
|
||||||
"https://doc.rust-lang.org/nightly"
|
|
||||||
} else {
|
|
||||||
"https://doc.rust-lang.org"
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
// This is a primitive so the url is done "by hand".
|
// This is a primitive so the url is done "by hand".
|
||||||
|
|
|
@ -521,3 +521,14 @@ crate fn has_doc_flag(attrs: ty::Attributes<'_>, flag: Symbol) -> bool {
|
||||||
&& attr.meta_item_list().map_or(false, |l| rustc_attr::list_contains_name(&l, flag))
|
&& attr.meta_item_list().map_or(false, |l| rustc_attr::list_contains_name(&l, flag))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return a channel suitable for using in a `doc.rust-lang.org/{channel}` format string.
|
||||||
|
crate fn doc_rust_lang_org_channel() -> &'static str {
|
||||||
|
match env!("CFG_RELEASE_CHANNEL") {
|
||||||
|
"stable" => env!("CFG_RELEASE_NUM"),
|
||||||
|
"beta" => "beta",
|
||||||
|
"nightly" | "dev" => "nightly",
|
||||||
|
// custom build of rustdoc maybe? link to the stable docs just in case
|
||||||
|
_ => "",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -498,15 +498,18 @@ crate fn run_global_ctxt(
|
||||||
let mut krate = tcx.sess.time("clean_crate", || clean::krate(&mut ctxt));
|
let mut krate = tcx.sess.time("clean_crate", || clean::krate(&mut ctxt));
|
||||||
|
|
||||||
if krate.module.doc_value().map(|d| d.is_empty()).unwrap_or(true) {
|
if krate.module.doc_value().map(|d| d.is_empty()).unwrap_or(true) {
|
||||||
let help = "The following guide may be of use:\n\
|
let help = format!(
|
||||||
https://doc.rust-lang.org/nightly/rustdoc/how-to-write-documentation.html";
|
"The following guide may be of use:\n\
|
||||||
|
https://doc.rust-lang.org/{}/rustdoc/how-to-write-documentation.html",
|
||||||
|
crate::doc_rust_lang_org_channel(),
|
||||||
|
);
|
||||||
tcx.struct_lint_node(
|
tcx.struct_lint_node(
|
||||||
crate::lint::MISSING_CRATE_LEVEL_DOCS,
|
crate::lint::MISSING_CRATE_LEVEL_DOCS,
|
||||||
DocContext::as_local_hir_id(tcx, krate.module.def_id).unwrap(),
|
DocContext::as_local_hir_id(tcx, krate.module.def_id).unwrap(),
|
||||||
|lint| {
|
|lint| {
|
||||||
let mut diag =
|
let mut diag =
|
||||||
lint.build("no documentation found for this crate's top-level module");
|
lint.build("no documentation found for this crate's top-level module");
|
||||||
diag.help(help);
|
diag.help(&help);
|
||||||
diag.emit();
|
diag.emit();
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
@ -82,6 +82,8 @@ use rustc_session::config::{make_crate_type_option, ErrorOutputType, RustcOptGro
|
||||||
use rustc_session::getopts;
|
use rustc_session::getopts;
|
||||||
use rustc_session::{early_error, early_warn};
|
use rustc_session::{early_error, early_warn};
|
||||||
|
|
||||||
|
use crate::clean::utils::doc_rust_lang_org_channel;
|
||||||
|
|
||||||
/// A macro to create a FxHashMap.
|
/// A macro to create a FxHashMap.
|
||||||
///
|
///
|
||||||
/// Example:
|
/// Example:
|
||||||
|
@ -597,7 +599,10 @@ fn usage(argv0: &str) {
|
||||||
}
|
}
|
||||||
println!("{}", options.usage(&format!("{} [options] <input>", argv0)));
|
println!("{}", options.usage(&format!("{} [options] <input>", argv0)));
|
||||||
println!(" @path Read newline separated options from `path`\n");
|
println!(" @path Read newline separated options from `path`\n");
|
||||||
println!("More information available at https://doc.rust-lang.org/rustdoc/what-is-rustdoc.html")
|
println!(
|
||||||
|
"More information available at https://doc.rust-lang.org/{}/rustdoc/what-is-rustdoc.html",
|
||||||
|
doc_rust_lang_org_channel()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A result type used by several functions under `main()`.
|
/// A result type used by several functions under `main()`.
|
||||||
|
|
|
@ -1925,16 +1925,10 @@ fn disambiguator_error(
|
||||||
) {
|
) {
|
||||||
diag_info.link_range = disambiguator_range;
|
diag_info.link_range = disambiguator_range;
|
||||||
report_diagnostic(cx.tcx, BROKEN_INTRA_DOC_LINKS, msg, &diag_info, |diag, _sp| {
|
report_diagnostic(cx.tcx, BROKEN_INTRA_DOC_LINKS, msg, &diag_info, |diag, _sp| {
|
||||||
let channel = match env!("CFG_RELEASE_CHANNEL") {
|
|
||||||
"stable" => env!("CFG_RELEASE_NUM"),
|
|
||||||
"beta" => "beta",
|
|
||||||
"nightly" | "dev" => "nightly",
|
|
||||||
// custom build of rustdoc maybe? link to the stable docs just in case
|
|
||||||
_ => "",
|
|
||||||
};
|
|
||||||
let msg = format!(
|
let msg = format!(
|
||||||
"see https://doc.rust-lang.org/{}/rustdoc/linking-to-items-by-name.html#namespaces-and-disambiguators for more info about disambiguators",
|
"see https://doc.rust-lang.org/{}/rustdoc/linking-to-items-by-name.html#namespaces-and-disambiguators \
|
||||||
channel,
|
for more info about disambiguators",
|
||||||
|
crate::doc_rust_lang_org_channel(),
|
||||||
);
|
);
|
||||||
diag.note(&msg);
|
diag.note(&msg);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue