Skip to content

Commit

Permalink
Rollup merge of rust-lang#74077 - sethp:docs/fix-intra-doc-primitive-…
Browse files Browse the repository at this point in the history
…link, r=Dylan-DPC

Use relative path for local links to primitives

Else, links to `char::foo` would point into `/path/to/src/libcore/std/primitive.char.html#method.foo`.

Split out from rust-lang#73804.
  • Loading branch information
Manishearth authored Jul 7, 2020
2 parents db84b32 + 8d267db commit e6fee38
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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".
Expand Down
18 changes: 18 additions & 0 deletions src/test/rustdoc/auxiliary/my-core.rs
Original file line number Diff line number Diff line change
@@ -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 {}
16 changes: 16 additions & 0 deletions src/test/rustdoc/intra-link-prim-methods-external-core.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// 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)]
#![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;
27 changes: 27 additions & 0 deletions src/test/rustdoc/intra-link-prim-methods-local.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#![deny(intra_doc_link_resolution_failure)]
#![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'

//! 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 {}
6 changes: 6 additions & 0 deletions src/test/rustdoc/intra-link-prim-methods.rs
Original file line number Diff line number Diff line change
@@ -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`].

0 comments on commit e6fee38

Please sign in to comment.