Generate links to definition in rustdoc source code pages by GuillaumeGomez · Pull Request #84176 · rust-lang/rust (original) (raw)

Description

This PR adds an option (disabled by default) to add links in the source code page on ident. So for for example:

mod other_module; struct Foo; fn bar() {}

fn x<T: other_module::Trait>(f: Foo, g: other_module::Whatever, t: &T) { let f: Foo = Foo; bar(); f.some_method(); }

In the example (mostly in the x function), other_module::Trait, Foo, other_module::Whatever, bar and some_method are now links (and other_module at the top too).

In case there is a type coming from another crate, it'll link to its documentation page and not its definition (but you can then click on [src] so I guess it's fine).

Another important detail: I voluntarily didn't add links for primitive types. I think we can discuss about adding links on them or not in a later PR (adding the support for them would require only a few lines).

Here is a video summing up everything I wrote above:

Peek.2021-04-13.23-15.mp4

Performance impact

So, on my computer, the performance remains more or less the same (which is quite surprising but that's a nice surprise). Here are the numbers:

Without the option:

With source to definition links generation (I enabled by default the option):

So no real change here (again, I'm very surprised by this fact).

For the size of the generated source files (only taking into account the src folder here since it's the only one impacted) by running du -shc . (when I am in the source folder).

Without the option: 11.939 MB
With the option: 12.611 MB

So not a big change here either. In all those docs, I ran grep -nR '<a class=' . | wc -l and got 43917. So there are quite a lot of links added. :)

cc @rust-lang/rustdoc
r? @jyn514