]> git.lizzy.rs Git - rust.git/commitdiff
Reuse logic for determining the channel in the rest of rustdoc
authorJoshua Nelson <jyn514@gmail.com>
Tue, 6 Apr 2021 18:51:36 +0000 (14:51 -0400)
committerJoshua Nelson <jyn514@gmail.com>
Wed, 7 Apr 2021 13:53:45 +0000 (09:53 -0400)
This doesn't update main.js because it's included as a fixed string.

src/librustdoc/clean/types.rs
src/librustdoc/clean/utils.rs
src/librustdoc/core.rs
src/librustdoc/lib.rs
src/librustdoc/passes/collect_intra_doc_links.rs

index a5629fe1d1186b378d08d986710c7e9fd4153c66..f3c9b987eb02ab82bfdf618b8e6b89f2aa41823a 100644 (file)
@@ -16,7 +16,6 @@
 use rustc_attr::{ConstStability, Deprecation, Stability, StabilityLevel};
 use rustc_data_structures::fx::{FxHashMap, FxHashSet};
 use rustc_data_structures::thin_vec::ThinVec;
-use rustc_feature::UnstableFeatures;
 use rustc_hir as hir;
 use rustc_hir::def::{CtorKind, Res};
 use rustc_hir::def_id::{CrateNum, DefId, DefIndex};
@@ -228,14 +227,9 @@ pub fn from_def_id_and_attrs_and_parts(
                                     "../".repeat(depth)
                                 }
                                 Some(&(_, _, ExternalLocation::Remote(ref s))) => s.to_string(),
-                                Some(&(_, _, ExternalLocation::Unknown)) | None => String::from(
-                                    // NOTE: intentionally doesn't pass crate name to avoid having
-                                    // different primitive links between crates
-                                    if UnstableFeatures::from_environment(None).is_nightly_build() {
-                                        "https://doc.rust-lang.org/nightly"
-                                    } else {
-                                        "https://doc.rust-lang.org"
-                                    },
+                                Some(&(_, _, ExternalLocation::Unknown)) | None => format!(
+                                    "https://doc.rust-lang.org/{}",
+                                    crate::doc_rust_lang_org_channel(),
                                 ),
                             };
                             // This is a primitive so the url is done "by hand".
index 9c0ed1480fef3846db5dc08accffab7b1f7f75b5..1e79bd0912884d3b922f0dc1891552f503c5c01e 100644 (file)
@@ -521,3 +521,14 @@ fn print_const_with_custom_print_scalar(tcx: TyCtxt<'_>, ct: &'tcx ty::Const<'tc
             && 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
+        _ => "",
+    }
+}
index 152094684adf42d169d04b0fb440bcc07033f958..c9fdaa50534dda942198dedce211efa4e618d9f2 100644 (file)
@@ -498,15 +498,18 @@ fn visit_item(&mut self, item: &ast::Item) {
     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) {
-        let help = "The following guide may be of use:\n\
-                https://doc.rust-lang.org/nightly/rustdoc/how-to-write-documentation.html";
+        let help = format!(
+            "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(
             crate::lint::MISSING_CRATE_LEVEL_DOCS,
             DocContext::as_local_hir_id(tcx, krate.module.def_id).unwrap(),
             |lint| {
                 let mut diag =
                     lint.build("no documentation found for this crate's top-level module");
-                diag.help(help);
+                diag.help(&help);
                 diag.emit();
             },
         );
index 241aa1f12df7e5e61d4e29265237915a53b1ae80..b9c4bbdceb27643206086cda1a9f10d1188208e9 100644 (file)
@@ -82,6 +82,8 @@
 use rustc_session::getopts;
 use rustc_session::{early_error, early_warn};
 
+use crate::clean::utils::doc_rust_lang_org_channel;
+
 /// A macro to create a FxHashMap.
 ///
 /// Example:
@@ -597,7 +599,10 @@ fn usage(argv0: &str) {
     }
     println!("{}", options.usage(&format!("{} [options] <input>", argv0)));
     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()`.
index 4be0e8823ee60f77a5bedba8a1a3ac97ecdbf996..4bc7544e33d1e98060d31a80fd28100740e18370 100644 (file)
@@ -1925,16 +1925,10 @@ fn disambiguator_error(
 ) {
     diag_info.link_range = disambiguator_range;
     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!(
-            "see https://doc.rust-lang.org/{}/rustdoc/linking-to-items-by-name.html#namespaces-and-disambiguators for more info about disambiguators",
-            channel,
+            "see https://doc.rust-lang.org/{}/rustdoc/linking-to-items-by-name.html#namespaces-and-disambiguators \
+             for more info about disambiguators",
+            crate::doc_rust_lang_org_channel(),
         );
         diag.note(&msg);
     });