From 81fbfc40594e0c74aa46bbf50225c4d923f1464b Mon Sep 17 00:00:00 2001 From: Seth Pellegrino Date: Sun, 5 Jul 2020 17:22:21 -0700 Subject: [PATCH 1/7] Use relative path for local links to primitives in libcore Else, links to `char::foo` would point into `/path/to/src/libcore/std/primitive.char.html#method.foo`. Split out from #73804. --- src/librustdoc/clean/types.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 6dec016cc2ee3..34f91bfec5a88 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -628,6 +628,7 @@ impl Attributes { /// Cache must be populated before call pub fn links(&self, krate: &CrateNum) -> Vec<(String, String)> { use crate::html::format::href; + use crate::html::render::CURRENT_DEPTH; self.links .iter() @@ -648,12 +649,13 @@ impl Attributes { if let Some(ref fragment) = *fragment { let cache = cache(); let url = match cache.extern_locations.get(krate) { - Some(&(_, ref src, ExternalLocation::Local)) => { - src.to_str().expect("invalid file path") + Some(&(_, _, ExternalLocation::Local)) => { + let depth = CURRENT_DEPTH.with(|l| l.get()); + "../".repeat(depth) } - Some(&(_, _, ExternalLocation::Remote(ref s))) => s, + Some(&(_, _, ExternalLocation::Remote(ref s))) => s.to_string(), Some(&(_, _, ExternalLocation::Unknown)) | None => { - "https://doc.rust-lang.org/nightly" + String::from("https://doc.rust-lang.org/nightly") } }; // This is a primitive so the url is done "by hand". From ee3a0f867e938f469cbbb422a76ed5662be2ecc7 Mon Sep 17 00:00:00 2001 From: Seth Pellegrino Date: Mon, 6 Jul 2020 08:46:44 -0700 Subject: [PATCH 2/7] Add guard to check for local `core` crate --- src/librustdoc/clean/types.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 34f91bfec5a88..d2ba34ccb8107 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -649,14 +649,16 @@ impl Attributes { if let Some(ref fragment) = *fragment { let cache = cache(); let url = match cache.extern_locations.get(krate) { - Some(&(_, _, ExternalLocation::Local)) => { + Some(&(ref krate_name, _, ExternalLocation::Local)) + if krate_name == "core" => + { let depth = CURRENT_DEPTH.with(|l| l.get()); "../".repeat(depth) } Some(&(_, _, ExternalLocation::Remote(ref s))) => s.to_string(), - Some(&(_, _, ExternalLocation::Unknown)) | None => { - String::from("https://doc.rust-lang.org/nightly") - } + Some(&(_, _, ExternalLocation::Local)) + | Some(&(_, _, ExternalLocation::Unknown)) + | None => String::from("https://doc.rust-lang.org/nightly"), }; // This is a primitive so the url is done "by hand". let tail = fragment.find('#').unwrap_or_else(|| fragment.len()); From 33a5d00efb4347736dd766c06cb9e0bcc0d6c377 Mon Sep 17 00:00:00 2001 From: Seth Pellegrino Date: Mon, 6 Jul 2020 19:35:07 -0700 Subject: [PATCH 3/7] Two new rustdoc tests for intra links They both produce less-than-desirable output (links going to docs.rust-lang.org), but I haven't figured out yet how to assert about them properly. --- src/test/rustdoc/auxiliary/my-core.rs | 18 ++++++++++++++++ .../intra-link-prim-methods-external-core.rs | 10 +++++++++ .../rustdoc/intra-link-prim-methods-local.rs | 21 +++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 src/test/rustdoc/auxiliary/my-core.rs create mode 100644 src/test/rustdoc/intra-link-prim-methods-external-core.rs create mode 100644 src/test/rustdoc/intra-link-prim-methods-local.rs diff --git a/src/test/rustdoc/auxiliary/my-core.rs b/src/test/rustdoc/auxiliary/my-core.rs new file mode 100644 index 0000000000000..999dfbdd8a3f5 --- /dev/null +++ b/src/test/rustdoc/auxiliary/my-core.rs @@ -0,0 +1,18 @@ +#![feature(no_core, lang_items)] +#![no_core] + +#[lang = "char"] +impl char { + pub fn len_utf8(self) -> usize { + 42 + } +} + +#[lang = "sized"] +pub trait Sized {} + +#[lang = "clone"] +pub trait Clone: Sized {} + +#[lang = "copy"] +pub trait Copy: Clone {} diff --git a/src/test/rustdoc/intra-link-prim-methods-external-core.rs b/src/test/rustdoc/intra-link-prim-methods-external-core.rs new file mode 100644 index 0000000000000..85e017e89b146 --- /dev/null +++ b/src/test/rustdoc/intra-link-prim-methods-external-core.rs @@ -0,0 +1,10 @@ +// aux-build:my-core.rs +// ignore-cross-compile + +#![deny(intra_doc_link_resolution_failure)] +#![feature(no_core, lang_items)] +#![no_core] + +//! A [`char`] and its [`char::len_utf8`]. + +extern crate my_core; diff --git a/src/test/rustdoc/intra-link-prim-methods-local.rs b/src/test/rustdoc/intra-link-prim-methods-local.rs new file mode 100644 index 0000000000000..c0be16885dae8 --- /dev/null +++ b/src/test/rustdoc/intra-link-prim-methods-local.rs @@ -0,0 +1,21 @@ +#![deny(intra_doc_link_resolution_failure)] +#![feature(no_core, lang_items)] +#![no_core] + +//! A [`char`] and its [`char::len_utf8`]. + +#[lang = "char"] +impl char { + pub fn len_utf8(self) -> usize { + 42 + } +} + +#[lang = "sized"] +pub trait Sized {} + +#[lang = "clone"] +pub trait Clone: Sized {} + +#[lang = "copy"] +pub trait Copy: Clone {} From 165aecbee31c3e628aaa8e6e7edbbd113f46e3f2 Mon Sep 17 00:00:00 2001 From: Seth Pellegrino Date: Mon, 6 Jul 2020 19:46:53 -0700 Subject: [PATCH 4/7] build extern docs as well --- src/test/rustdoc/intra-link-prim-methods-external-core.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/rustdoc/intra-link-prim-methods-external-core.rs b/src/test/rustdoc/intra-link-prim-methods-external-core.rs index 85e017e89b146..a7f243f63a893 100644 --- a/src/test/rustdoc/intra-link-prim-methods-external-core.rs +++ b/src/test/rustdoc/intra-link-prim-methods-external-core.rs @@ -1,4 +1,5 @@ // aux-build:my-core.rs +// build-aux-docs // ignore-cross-compile #![deny(intra_doc_link_resolution_failure)] From 865b930bc99680bd170a677c095a2116a5c4159d Mon Sep 17 00:00:00 2001 From: Seth Pellegrino Date: Tue, 7 Jul 2020 10:23:29 -0700 Subject: [PATCH 5/7] Assert current behavior for links For the two of these tests that have a local `char` to link to, this behavior isn't what's expected, but is what's happening presently. --- src/test/rustdoc/intra-link-prim-methods-external-core.rs | 4 ++++ src/test/rustdoc/intra-link-prim-methods-local.rs | 4 ++++ src/test/rustdoc/intra-link-prim-methods.rs | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/src/test/rustdoc/intra-link-prim-methods-external-core.rs b/src/test/rustdoc/intra-link-prim-methods-external-core.rs index a7f243f63a893..f3953ef3f2eb4 100644 --- a/src/test/rustdoc/intra-link-prim-methods-external-core.rs +++ b/src/test/rustdoc/intra-link-prim-methods-external-core.rs @@ -6,6 +6,10 @@ #![feature(no_core, lang_items)] #![no_core] +// @has intra_link_prim_methods_external_core/index.html +// @has - '//*[@id="main"]//a[@href="https://doc.rust-lang.org/nightly/std/primitive.char.html"]' 'char' +// @has - '//*[@id="main"]//a[@href="https://doc.rust-lang.org/nightly/std/primitive.char.html#method.len_utf8"]' 'char::len_utf8' + //! A [`char`] and its [`char::len_utf8`]. extern crate my_core; diff --git a/src/test/rustdoc/intra-link-prim-methods-local.rs b/src/test/rustdoc/intra-link-prim-methods-local.rs index c0be16885dae8..ed72b5f40de87 100644 --- a/src/test/rustdoc/intra-link-prim-methods-local.rs +++ b/src/test/rustdoc/intra-link-prim-methods-local.rs @@ -2,6 +2,10 @@ #![feature(no_core, lang_items)] #![no_core] +// @has intra_link_prim_methods_local/index.html +// @has - '//*[@id="main"]//a[@href="https://doc.rust-lang.org/nightly/std/primitive.char.html"]' 'char' +// @has - '//*[@id="main"]//a[@href="https://doc.rust-lang.org/nightly/std/primitive.char.html#method.len_utf8"]' 'char::len_utf8' + //! A [`char`] and its [`char::len_utf8`]. #[lang = "char"] diff --git a/src/test/rustdoc/intra-link-prim-methods.rs b/src/test/rustdoc/intra-link-prim-methods.rs index af0426b22c557..ba050968ce0ac 100644 --- a/src/test/rustdoc/intra-link-prim-methods.rs +++ b/src/test/rustdoc/intra-link-prim-methods.rs @@ -1,3 +1,7 @@ #![deny(intra_doc_link_resolution_failure)] +// @has intra_link_prim_methods/index.html +// @has - '//*[@id="main"]//a[@href="https://doc.rust-lang.org/nightly/std/primitive.char.html"]' 'char' +// @has - '//*[@id="main"]//a[@href="https://doc.rust-lang.org/nightly/std/primitive.char.html#method.len_utf8"]' 'char::len_utf8' + //! A [`char`] and its [`char::len_utf8`]. From f258d98f65ef1408a6045f5ca7873371720409c2 Mon Sep 17 00:00:00 2001 From: Seth Pellegrino Date: Tue, 7 Jul 2020 10:39:10 -0700 Subject: [PATCH 6/7] ignore-tidy-linelength for @has assertions --- src/test/rustdoc/intra-link-prim-methods-external-core.rs | 1 + src/test/rustdoc/intra-link-prim-methods-local.rs | 2 ++ src/test/rustdoc/intra-link-prim-methods.rs | 2 ++ 3 files changed, 5 insertions(+) diff --git a/src/test/rustdoc/intra-link-prim-methods-external-core.rs b/src/test/rustdoc/intra-link-prim-methods-external-core.rs index f3953ef3f2eb4..1569cf4734075 100644 --- a/src/test/rustdoc/intra-link-prim-methods-external-core.rs +++ b/src/test/rustdoc/intra-link-prim-methods-external-core.rs @@ -1,6 +1,7 @@ // aux-build:my-core.rs // build-aux-docs // ignore-cross-compile +// ignore-tidy-linelength #![deny(intra_doc_link_resolution_failure)] #![feature(no_core, lang_items)] diff --git a/src/test/rustdoc/intra-link-prim-methods-local.rs b/src/test/rustdoc/intra-link-prim-methods-local.rs index ed72b5f40de87..ea64efe6d6701 100644 --- a/src/test/rustdoc/intra-link-prim-methods-local.rs +++ b/src/test/rustdoc/intra-link-prim-methods-local.rs @@ -2,6 +2,8 @@ #![feature(no_core, lang_items)] #![no_core] +// ignore-tidy-linelength + // @has intra_link_prim_methods_local/index.html // @has - '//*[@id="main"]//a[@href="https://doc.rust-lang.org/nightly/std/primitive.char.html"]' 'char' // @has - '//*[@id="main"]//a[@href="https://doc.rust-lang.org/nightly/std/primitive.char.html#method.len_utf8"]' 'char::len_utf8' diff --git a/src/test/rustdoc/intra-link-prim-methods.rs b/src/test/rustdoc/intra-link-prim-methods.rs index ba050968ce0ac..76636b80b5eb5 100644 --- a/src/test/rustdoc/intra-link-prim-methods.rs +++ b/src/test/rustdoc/intra-link-prim-methods.rs @@ -1,5 +1,7 @@ #![deny(intra_doc_link_resolution_failure)] +// ignore-tidy-linelength + // @has intra_link_prim_methods/index.html // @has - '//*[@id="main"]//a[@href="https://doc.rust-lang.org/nightly/std/primitive.char.html"]' 'char' // @has - '//*[@id="main"]//a[@href="https://doc.rust-lang.org/nightly/std/primitive.char.html#method.len_utf8"]' 'char::len_utf8' From 8d267db31a767f22f07e06439ae682329c22bef1 Mon Sep 17 00:00:00 2001 From: Seth Pellegrino Date: Tue, 7 Jul 2020 14:15:31 -0700 Subject: [PATCH 7/7] Revert "Add guard to check for local `core` crate" This reverts commit ee3a0f867e938f469cbbb422a76ed5662be2ecc7. --- src/librustdoc/clean/types.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index d2ba34ccb8107..34f91bfec5a88 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -649,16 +649,14 @@ impl Attributes { if let Some(ref fragment) = *fragment { let cache = cache(); let url = match cache.extern_locations.get(krate) { - Some(&(ref krate_name, _, ExternalLocation::Local)) - if krate_name == "core" => - { + Some(&(_, _, ExternalLocation::Local)) => { let depth = CURRENT_DEPTH.with(|l| l.get()); "../".repeat(depth) } Some(&(_, _, ExternalLocation::Remote(ref s))) => s.to_string(), - Some(&(_, _, ExternalLocation::Local)) - | Some(&(_, _, ExternalLocation::Unknown)) - | None => String::from("https://doc.rust-lang.org/nightly"), + Some(&(_, _, ExternalLocation::Unknown)) | None => { + String::from("https://doc.rust-lang.org/nightly") + } }; // This is a primitive so the url is done "by hand". let tail = fragment.find('#').unwrap_or_else(|| fragment.len());