diff options
| author | Seth Pellegrino <seth@codecopse.net> | 2020-07-05 17:22:21 -0700 |
|---|---|---|
| committer | Seth Pellegrino <seth@codecopse.net> | 2020-07-05 17:22:21 -0700 |
| commit | 81fbfc40594e0c74aa46bbf50225c4d923f1464b (patch) | |
| tree | b6b83b98420fecf119bc694da5a42bc4b308e5b1 | |
| parent | 394e1b40d264aa6928811919c1124fa248e7d802 (diff) | |
| download | rust-81fbfc40594e0c74aa46bbf50225c4d923f1464b.tar.gz rust-81fbfc40594e0c74aa46bbf50225c4d923f1464b.zip | |
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.
| -rw-r--r-- | src/librustdoc/clean/types.rs | 10 |
1 files 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 @@ 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". |
