Commit 375c7fb
committed
Auto merge of #47046 - Manishearth:intra-doc-links, r=eddyb,GuillaumeGomez,QuietMisdreavus,Manishearth
Implement RFC 1946 - intra-rustdoc links
rust-lang/rfcs#1946 #43466
Note for reviewers: The plain line counts are a little inflated because of how the markdown link parsing was done. [Read the file diff with "whitespace only" changes removed](https://github.com/rust-lang/rust/pull/47046/files?w=1) to get a better view of what actually changed there.
This pulls the name/path resolution mechanisms out of the compiler and runs it on the markdown in a crate's docs, so that links can be made to `SomeStruct` directly rather than finding the folder path to `struct.SomeStruct.html`. Check the `src/test/rustdoc/intra-paths.rs` test in this PR for a demo. The change was... a little invasive, but unlocks a really powerful mechanism for writing documentation that doesn't care about where an item was written to on the hard disk.
Items included:
- [x] Make work with the hoedown renderer
- [x] Handle relative paths
- [x] Parse out the "path ambiguities" qualifiers (`[crate foo]`, `[struct Foo]`, `[foo()]`, `[static FOO]`, `[foo!]`, etc)
- [x] Resolve foreign macros
- [x] Resolve local macros
- [x] Handle the use of inner/outer attributes giving different resolution scopes (handling for non-modules pushed to different PR)
Items not included:
- [ ] Make sure cross-crate inlining works (blocked on refactor described in #47046 (comment))
- [ ] Implied Shortcut Reference Links (where just doing `[::std::iter::Iterator][]` without a reference anchor will resolve using the reference name rather than the link target) (requires modifying the markdown parser - blocked on Hoedown/Pulldown switch and pulldown-cmark/pulldown-cmark#121)
- [ ] Handle enum variants and UFCS methods (Enum variants link to the enum page, associated methods don't link at all)
- [ ] Emit more warnings/errors when things fail to resolve (linking to a value-namespaced item without a qualifier will emit an error, otherwise the link is just treated as a url, not a rust path)
- [ ] Give better spans for resolution errors (currently the span for the first doc comment is used)
- [ ] Check for inner doc comments on things that aren't modules
I'm making the PR, but it should be noted that most of the work was done by Misdreavus 😄
(Editor's note: This has become a lie, check that commit log, Manish did a ton of work after this PR was opened `>_>`)File tree
17 files changed
+944
-264
lines changed- src
- librustc_driver
- librustc_resolve
- librustc/hir
- librustdoc
- clean
- html
- test/rustdoc
- tools/error_index_generator
17 files changed
+944
-264
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
151 | 151 | | |
152 | 152 | | |
153 | 153 | | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
154 | 159 | | |
155 | 160 | | |
156 | 161 | | |
| |||
3625 | 3630 | | |
3626 | 3631 | | |
3627 | 3632 | | |
3628 | | - | |
3629 | | - | |
3630 | | - | |
3631 | | - | |
3632 | | - | |
3633 | | - | |
3634 | | - | |
3635 | | - | |
3636 | | - | |
3637 | | - | |
| 3633 | + | |
3638 | 3634 | | |
3639 | 3635 | | |
3640 | 3636 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| |||
139 | 139 | | |
140 | 140 | | |
141 | 141 | | |
| 142 | + | |
142 | 143 | | |
143 | 144 | | |
144 | 145 | | |
| |||
562 | 563 | | |
563 | 564 | | |
564 | 565 | | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
565 | 572 | | |
566 | 573 | | |
567 | 574 | | |
| |||
578 | 585 | | |
579 | 586 | | |
580 | 587 | | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
581 | 637 | | |
582 | 638 | | |
583 | 639 | | |
| |||
666 | 722 | | |
667 | 723 | | |
668 | 724 | | |
669 | | - | |
670 | | - | |
671 | | - | |
672 | | - | |
673 | | - | |
674 | | - | |
675 | | - | |
676 | 725 | | |
677 | 726 | | |
678 | 727 | | |
679 | 728 | | |
680 | 729 | | |
681 | | - | |
| 730 | + | |
682 | 731 | | |
683 | 732 | | |
684 | 733 | | |
| |||
855 | 904 | | |
856 | 905 | | |
857 | 906 | | |
858 | | - | |
| 907 | + | |
859 | 908 | | |
860 | | - | |
861 | | - | |
862 | | - | |
863 | | - | |
864 | | - | |
865 | | - | |
866 | | - | |
867 | | - | |
868 | | - | |
869 | | - | |
870 | | - | |
871 | | - | |
872 | | - | |
| 909 | + | |
873 | 910 | | |
874 | 911 | | |
875 | 912 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
| 70 | + | |
70 | 71 | | |
71 | 72 | | |
72 | 73 | | |
| |||
1320 | 1321 | | |
1321 | 1322 | | |
1322 | 1323 | | |
| 1324 | + | |
1323 | 1325 | | |
1324 | 1326 | | |
1325 | 1327 | | |
| |||
1407 | 1409 | | |
1408 | 1410 | | |
1409 | 1411 | | |
| 1412 | + | |
| 1413 | + | |
| 1414 | + | |
| 1415 | + | |
| 1416 | + | |
| 1417 | + | |
| 1418 | + | |
| 1419 | + | |
| 1420 | + | |
| 1421 | + | |
| 1422 | + | |
| 1423 | + | |
| 1424 | + | |
| 1425 | + | |
| 1426 | + | |
| 1427 | + | |
| 1428 | + | |
| 1429 | + | |
| 1430 | + | |
| 1431 | + | |
| 1432 | + | |
| 1433 | + | |
| 1434 | + | |
| 1435 | + | |
| 1436 | + | |
| 1437 | + | |
| 1438 | + | |
| 1439 | + | |
| 1440 | + | |
| 1441 | + | |
| 1442 | + | |
| 1443 | + | |
| 1444 | + | |
| 1445 | + | |
| 1446 | + | |
| 1447 | + | |
| 1448 | + | |
| 1449 | + | |
| 1450 | + | |
| 1451 | + | |
| 1452 | + | |
| 1453 | + | |
| 1454 | + | |
| 1455 | + | |
| 1456 | + | |
| 1457 | + | |
| 1458 | + | |
| 1459 | + | |
| 1460 | + | |
| 1461 | + | |
| 1462 | + | |
| 1463 | + | |
| 1464 | + | |
| 1465 | + | |
| 1466 | + | |
| 1467 | + | |
| 1468 | + | |
| 1469 | + | |
| 1470 | + | |
| 1471 | + | |
| 1472 | + | |
| 1473 | + | |
| 1474 | + | |
| 1475 | + | |
| 1476 | + | |
1410 | 1477 | | |
1411 | 1478 | | |
1412 | 1479 | | |
| |||
1418 | 1485 | | |
1419 | 1486 | | |
1420 | 1487 | | |
1421 | | - | |
| 1488 | + | |
1422 | 1489 | | |
1423 | 1490 | | |
1424 | 1491 | | |
1425 | 1492 | | |
1426 | 1493 | | |
1427 | | - | |
| 1494 | + | |
1428 | 1495 | | |
1429 | 1496 | | |
1430 | 1497 | | |
1431 | | - | |
1432 | | - | |
1433 | | - | |
1434 | | - | |
1435 | | - | |
1436 | | - | |
1437 | | - | |
1438 | | - | |
1439 | 1498 | | |
1440 | 1499 | | |
1441 | 1500 | | |
| |||
1538 | 1597 | | |
1539 | 1598 | | |
1540 | 1599 | | |
| 1600 | + | |
1541 | 1601 | | |
1542 | 1602 | | |
1543 | 1603 | | |
| |||
1833 | 1893 | | |
1834 | 1894 | | |
1835 | 1895 | | |
1836 | | - | |
1837 | | - | |
| 1896 | + | |
| 1897 | + | |
1838 | 1898 | | |
1839 | 1899 | | |
1840 | 1900 | | |
| |||
1845 | 1905 | | |
1846 | 1906 | | |
1847 | 1907 | | |
1848 | | - | |
| 1908 | + | |
1849 | 1909 | | |
1850 | 1910 | | |
1851 | 1911 | | |
1852 | 1912 | | |
| 1913 | + | |
1853 | 1914 | | |
1854 | | - | |
| 1915 | + | |
1855 | 1916 | | |
1856 | 1917 | | |
1857 | 1918 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
409 | 409 | | |
410 | 410 | | |
411 | 411 | | |
412 | | - | |
| 412 | + | |
413 | 413 | | |
414 | 414 | | |
415 | 415 | | |
| |||
755 | 755 | | |
756 | 756 | | |
757 | 757 | | |
| 758 | + | |
| 759 | + | |
758 | 760 | | |
759 | | - | |
760 | 761 | | |
761 | 762 | | |
762 | 763 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
138 | | - | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
139 | 143 | | |
140 | 144 | | |
141 | 145 | | |
| |||
0 commit comments