From 81fbfc40594e0c74aa46bbf50225c4d923f1464b Mon Sep 17 00:00:00 2001 From: Seth Pellegrino Date: Sun, 5 Jul 2020 17:22:21 -0700 Subject: [PATCH 1/9] 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 6dec016cc2e..34f91bfec5a 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -628,6 +628,7 @@ pub fn collapsed_doc_value(&self) -> Option { /// 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 @@ pub fn links(&self, krate: &CrateNum) -> Vec<(String, String)> { 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/9] 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 34f91bfec5a..d2ba34ccb81 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -649,14 +649,16 @@ pub fn links(&self, krate: &CrateNum) -> Vec<(String, String)> { 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/9] 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 00000000000..999dfbdd8a3 --- /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 00000000000..85e017e89b1 --- /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 00000000000..c0be16885da --- /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/9] 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 85e017e89b1..a7f243f63a8 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/9] 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 a7f243f63a8..f3953ef3f2e 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 c0be16885da..ed72b5f40de 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 af0426b22c5..ba050968ce0 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/9] 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 f3953ef3f2e..1569cf47340 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 ed72b5f40de..ea64efe6d67 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 ba050968ce0..76636b80b5e 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/9] 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 d2ba34ccb81..34f91bfec5a 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -649,16 +649,14 @@ pub fn links(&self, krate: &CrateNum) -> Vec<(String, String)> { 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()); From 9366458c58a60b9573f45f1c407bd4c7f2fa1876 Mon Sep 17 00:00:00 2001 From: Seth Pellegrino Date: Wed, 8 Jul 2020 08:20:43 -0700 Subject: [PATCH 8/9] Apply #![crate_type = "rlib"] directly to the linker --- src/test/rustdoc/auxiliary/my-core.rs | 1 + src/test/rustdoc/intra-link-prim-methods-external-core.rs | 1 + src/test/rustdoc/intra-link-prim-methods-local.rs | 1 + 3 files changed, 3 insertions(+) diff --git a/src/test/rustdoc/auxiliary/my-core.rs b/src/test/rustdoc/auxiliary/my-core.rs index 999dfbdd8a3..54e986be9ec 100644 --- a/src/test/rustdoc/auxiliary/my-core.rs +++ b/src/test/rustdoc/auxiliary/my-core.rs @@ -1,5 +1,6 @@ #![feature(no_core, lang_items)] #![no_core] +#![crate_type="rlib"] #[lang = "char"] impl char { 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 1569cf47340..b9bdd86ecc5 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,7 @@ #![deny(intra_doc_link_resolution_failure)] #![feature(no_core, lang_items)] #![no_core] +#![crate_type = "rlib"] // @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' diff --git a/src/test/rustdoc/intra-link-prim-methods-local.rs b/src/test/rustdoc/intra-link-prim-methods-local.rs index ea64efe6d67..d24cd2cbb5e 100644 --- a/src/test/rustdoc/intra-link-prim-methods-local.rs +++ b/src/test/rustdoc/intra-link-prim-methods-local.rs @@ -1,6 +1,7 @@ #![deny(intra_doc_link_resolution_failure)] #![feature(no_core, lang_items)] #![no_core] +#![crate_type = "rlib"] // ignore-tidy-linelength From 56b6b44641f0dc999a63b478c93af5279ad7464f Mon Sep 17 00:00:00 2001 From: Seth Pellegrino Date: Wed, 8 Jul 2020 09:48:15 -0700 Subject: [PATCH 9/9] Avoid running test on Windows platforms There don't seem to be any other compiletests that are 1) building a standalone "no_core" create and then 2) trying to link against it. There seems to be a platform-specific limitation in doing so: ``` 2020-07-08T16:07:42.9419409Z = note: Creating library D:\a\rust\rust\build\i686-pc-windows-msvc\test\rustdoc\intra-link-prim-methods-external-core\auxiliary\my_core.dll.lib and object D:\a\rust\rust\build\i686-pc-windows-msvc\test\rustdoc\intra-link-prim-methods-external-core\auxiliary\my_core.dll.exp 2020-07-08T16:07:42.9419810Z LINK : error LNK2001: unresolved external symbol __DllMainCRTStartup@12 2020-07-08T16:07:42.9420032Z D:\a\rust\rust\build\i686-pc-windows-msvc\test\rustdoc\intra-link-prim-methods-external-core\auxiliary\my_core.dll : fatal error LNK1120: 1 unresolved externals ``` Possibly this could be resolved by adding a `__DllMainCRTStartup` or `__DllMainCRTStartup@12` symbol in an architecture- and platform-specific way. --- 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 b9bdd86ecc5..e09d36594ed 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-windows // ignore-tidy-linelength #![deny(intra_doc_link_resolution_failure)]