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". diff --git a/src/test/rustdoc/auxiliary/my-core.rs b/src/test/rustdoc/auxiliary/my-core.rs new file mode 100644 index 00000000000..54e986be9ec --- /dev/null +++ b/src/test/rustdoc/auxiliary/my-core.rs @@ -0,0 +1,19 @@ +#![feature(no_core, lang_items)] +#![no_core] +#![crate_type="rlib"] + +#[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..e09d36594ed --- /dev/null +++ b/src/test/rustdoc/intra-link-prim-methods-external-core.rs @@ -0,0 +1,18 @@ +// aux-build:my-core.rs +// build-aux-docs +// ignore-cross-compile +// ignore-windows +// ignore-tidy-linelength + +#![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' +// @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 new file mode 100644 index 00000000000..d24cd2cbb5e --- /dev/null +++ b/src/test/rustdoc/intra-link-prim-methods-local.rs @@ -0,0 +1,28 @@ +#![deny(intra_doc_link_resolution_failure)] +#![feature(no_core, lang_items)] +#![no_core] +#![crate_type = "rlib"] + +// 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' + +//! 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 {} diff --git a/src/test/rustdoc/intra-link-prim-methods.rs b/src/test/rustdoc/intra-link-prim-methods.rs index af0426b22c5..76636b80b5e 100644 --- a/src/test/rustdoc/intra-link-prim-methods.rs +++ b/src/test/rustdoc/intra-link-prim-methods.rs @@ -1,3 +1,9 @@ #![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' + //! A [`char`] and its [`char::len_utf8`].