Skip to content

Commit 81fbfc4

Browse files
committed
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.
1 parent 394e1b4 commit 81fbfc4

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/librustdoc/clean/types.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,7 @@ impl Attributes {
628628
/// Cache must be populated before call
629629
pub fn links(&self, krate: &CrateNum) -> Vec<(String, String)> {
630630
use crate::html::format::href;
631+
use crate::html::render::CURRENT_DEPTH;
631632

632633
self.links
633634
.iter()
@@ -648,12 +649,13 @@ impl Attributes {
648649
if let Some(ref fragment) = *fragment {
649650
let cache = cache();
650651
let url = match cache.extern_locations.get(krate) {
651-
Some(&(_, ref src, ExternalLocation::Local)) => {
652-
src.to_str().expect("invalid file path")
652+
Some(&(_, _, ExternalLocation::Local)) => {
653+
let depth = CURRENT_DEPTH.with(|l| l.get());
654+
"../".repeat(depth)
653655
}
654-
Some(&(_, _, ExternalLocation::Remote(ref s))) => s,
656+
Some(&(_, _, ExternalLocation::Remote(ref s))) => s.to_string(),
655657
Some(&(_, _, ExternalLocation::Unknown)) | None => {
656-
"https://doc.rust-lang.org/nightly"
658+
String::from("https://doc.rust-lang.org/nightly")
657659
}
658660
};
659661
// This is a primitive so the url is done "by hand".

0 commit comments

Comments
 (0)