Rustdoc: include crate name in links for local primitives by gurry · Pull Request #121490 · rust-lang/rust (original) (raw)

Fixes #121106.

This change makes links to primitives easier to use when the path of the page where they will be embedded is not known beforehand such as when we generate impls dynamically from the register_type_impls method in main.js, which is exactly what is happening in #121106.

An example to show the effect of this change: earlier, if the current page in cx.current inside primitive_link_fragment() was std::simd::prelude::Simd the generated path would be ../../primitive.<prim>.html. Now it would be ../../../std/primitive.<prim>.html instead.

A side effect of the change is that local primitive links everywhere will now contain the crate name, even outside of the dynamic situation mentioned above. I'm not sure if there are any major downsides of that other than making the links a bit longer. Ideally I wanted to restrict this behaviour change to only the dynamic cases. We could have achieved that by passing an additional bool arg to primitive_link_fragment(), but it felt awkward to do so. Any alternative suggestions are welcome.