Skip to content

Commit e0bfa5c

Browse files
committed
Rustdoc: include crate name in links for local primitives
It makes the link easier to use in cases in which the path of the page where it will be embedded is not known beforehand such as when we generate impls dynamically from `register_type_impls` method in `main.js` Earlier for local primitives we would generate a path that was relative to the current page depth passed in `cx.current` . e.g if the current page was `std::simd::prelude::Simd` the generated path would be `../../primitive.<prim>.html` After this change the path will first take you to the the wesite root and add the crate name. e.g. for `std::simd::prelude::Simd` the path now will be `../../../std/primitive.<prim>.html`
1 parent a28d221 commit e0bfa5c

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/librustdoc/html/format.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -879,11 +879,16 @@ fn primitive_link_fragment(
879879
match m.primitive_locations.get(&prim) {
880880
Some(&def_id) if def_id.is_local() => {
881881
let len = cx.current.len();
882-
let len = if len == 0 { 0 } else { len - 1 };
882+
let path = if len == 0 {
883+
let cname_sym = ExternalCrate { crate_num: def_id.krate }.name(cx.tcx());
884+
format!("{cname_sym}/")
885+
} else {
886+
"../".repeat(len - 1)
887+
};
883888
write!(
884889
f,
885890
"<a class=\"primitive\" href=\"{}primitive.{}.html{fragment}\">",
886-
"../".repeat(len),
891+
path,
887892
prim.as_sym()
888893
)?;
889894
needs_termination = true;

0 commit comments

Comments
 (0)