Commit e411480
authored
Rollup merge of #149274 - GuillaumeGomez:tyalias-method-link, r=lolbinarycat
Fix invalid link generation for type alias methods
Fixes #149205.
That one was quite the wild ride. First commit is the actual fix, the second commit is just a small name variable improvement while I was going through the code. Anyway, let's go through it:
* We don't generate directly implementations in the HTML files for local impls (which I think is a mistake and should be changed, gonna do that as a follow-up) but instead generate a JS file for each type alias containing the HTML for these impls.
* So in `write_shared.rs::TypeAliasPart::get`, when generating the JS file, we generate the impl into a `String` by calling `render_impl`. This method expects an `AssocItemLink` to help it generate the correct link to the item (I'm planning to also remove this enum because it's yet another way to generate anchors/hrefs).
* Problem was: we call the `provided_trait_methods` method on the impl item... which is empty if not a trait impl. This becomes an issue when we arrive in `render::assoc_href_attr` because of this code:
```rust
AssocItemLink::GotoSource(did, provided_methods) => {
let item_type = match item_type {
ItemType::Method | ItemType::TyMethod => {
if provided_methods.contains(&name) {
ItemType::Method
} else {
ItemType::TyMethod
}
}
item_type => item_type,
};
// ...
}
```
Since `provided_methods` is always empty, it means all methods on type aliases will be `TyMethod`, generating `#tymethod.` URLs instead of `#method.`.
* So generating `AssocItemLink::GoToSource` only on traits (when `provided_trait_methods` is supposed to return something) was the fix.
* And finally, because it's (currently) generating implementations only through JS, it means we cannot test it in `tests/rustdoc` so I had to write the test in `tests/rustdoc-gui`. Once I change how we generate local implementations for type aliases, I'll move it to `tests/rustdoc`.
r? `@lolbinarycat`File tree
4 files changed
+26
-15
lines changed- src/librustdoc/html/render
- tests/rustdoc-gui
- src/test_docs
4 files changed
+26
-15
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2025 | 2025 | | |
2026 | 2026 | | |
2027 | 2027 | | |
2028 | | - | |
2029 | | - | |
2030 | | - | |
2031 | | - | |
2032 | | - | |
| 2028 | + | |
| 2029 | + | |
| 2030 | + | |
2033 | 2031 | | |
2034 | | - | |
| 2032 | + | |
2035 | 2033 | | |
2036 | 2034 | | |
2037 | 2035 | | |
| |||
2041 | 2039 | | |
2042 | 2040 | | |
2043 | 2041 | | |
2044 | | - | |
| 2042 | + | |
2045 | 2043 | | |
2046 | 2044 | | |
2047 | 2045 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
568 | 568 | | |
569 | 569 | | |
570 | 570 | | |
571 | | - | |
572 | | - | |
573 | | - | |
574 | | - | |
575 | | - | |
576 | | - | |
| 571 | + | |
| 572 | + | |
577 | 573 | | |
578 | | - | |
| 574 | + | |
579 | 575 | | |
580 | 576 | | |
581 | 577 | | |
582 | | - | |
| 578 | + | |
583 | 579 | | |
584 | 580 | | |
585 | 581 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
786 | 786 | | |
787 | 787 | | |
788 | 788 | | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
0 commit comments