This repository was archived by the owner on May 28, 2025. It is now read-only.
Commit e2f7957
committed
Auto merge of rust-lang#84176 - GuillaumeGomez:src-to-definition, r=jyn514
Generate links to definition in rustdoc source code pages
## Description
This PR adds an option (disabled by default) to add links in the source code page on ident. So for for example:
```rust
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:
https://user-images.githubusercontent.com/3050060/114622354-21307b00-9cae-11eb-834d-f6d8178a37bd.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:
* core: 1m 21s
* alloc: 26.78s
* std: 27.30s
* proc_macro: 4.50s
With source to definition links generation (I enabled by default the option):
* core: 1m 25s
* alloc: 25.76s
* std: 27.07s
* proc_macro: 4.66s
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`File tree
30 files changed
+707
-131
lines changed- compiler
- rustc_errors/src
- rustc_session/src
- src
- librustdoc
- clean
- html
- highlight
- fixtures
- render
- static/css
- test
- rustdoc-ui
- rustdoc
- auxiliary
30 files changed
+707
-131
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
342 | 342 | | |
343 | 343 | | |
344 | 344 | | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
345 | 348 | | |
346 | 349 | | |
347 | 350 | | |
| |||
456 | 459 | | |
457 | 460 | | |
458 | 461 | | |
| 462 | + | |
459 | 463 | | |
460 | 464 | | |
461 | 465 | | |
462 | 466 | | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
463 | 475 | | |
464 | 476 | | |
465 | 477 | | |
| |||
818 | 830 | | |
819 | 831 | | |
820 | 832 | | |
821 | | - | |
| 833 | + | |
822 | 834 | | |
823 | 835 | | |
824 | 836 | | |
| |||
1035 | 1047 | | |
1036 | 1048 | | |
1037 | 1049 | | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
1038 | 1053 | | |
1039 | 1054 | | |
1040 | 1055 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
500 | 500 | | |
501 | 501 | | |
502 | 502 | | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
503 | 507 | | |
504 | 508 | | |
505 | 509 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
101 | | - | |
| 101 | + | |
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
517 | 517 | | |
518 | 518 | | |
519 | 519 | | |
520 | | - | |
| 520 | + | |
521 | 521 | | |
522 | 522 | | |
523 | 523 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
98 | | - | |
| 98 | + | |
| 99 | + | |
99 | 100 | | |
100 | 101 | | |
101 | 102 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
343 | 343 | | |
344 | 344 | | |
345 | 345 | | |
346 | | - | |
| 346 | + | |
347 | 347 | | |
348 | 348 | | |
349 | 349 | | |
| |||
1943 | 1943 | | |
1944 | 1944 | | |
1945 | 1945 | | |
1946 | | - | |
1947 | | - | |
1948 | | - | |
1949 | | - | |
| 1946 | + | |
| 1947 | + | |
| 1948 | + | |
| 1949 | + | |
| 1950 | + | |
1950 | 1951 | | |
1951 | 1952 | | |
1952 | 1953 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
276 | 276 | | |
277 | 277 | | |
278 | 278 | | |
| 279 | + | |
| 280 | + | |
279 | 281 | | |
280 | 282 | | |
281 | 283 | | |
| |||
655 | 657 | | |
656 | 658 | | |
657 | 659 | | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
658 | 669 | | |
659 | 670 | | |
660 | 671 | | |
| |||
721 | 732 | | |
722 | 733 | | |
723 | 734 | | |
| 735 | + | |
724 | 736 | | |
725 | 737 | | |
726 | 738 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
484 | 484 | | |
485 | 485 | | |
486 | 486 | | |
487 | | - | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
488 | 492 | | |
489 | 493 | | |
490 | 494 | | |
| |||
495 | 499 | | |
496 | 500 | | |
497 | 501 | | |
| 502 | + | |
498 | 503 | | |
499 | 504 | | |
500 | 505 | | |
| |||
508 | 513 | | |
509 | 514 | | |
510 | 515 | | |
| 516 | + | |
511 | 517 | | |
512 | 518 | | |
513 | 519 | | |
| |||
522 | 528 | | |
523 | 529 | | |
524 | 530 | | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
525 | 537 | | |
526 | 538 | | |
527 | 539 | | |
| |||
536 | 548 | | |
537 | 549 | | |
538 | 550 | | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
539 | 555 | | |
540 | 556 | | |
541 | 557 | | |
| |||
0 commit comments