Commit f72608c
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 | |
|---|---|---|---|
| |||
2020 | 2020 | | |
2021 | 2021 | | |
2022 | 2022 | | |
2023 | | - | |
2024 | | - | |
2025 | | - | |
2026 | | - | |
2027 | | - | |
| 2023 | + | |
| 2024 | + | |
| 2025 | + | |
2028 | 2026 | | |
2029 | | - | |
| 2027 | + | |
2030 | 2028 | | |
2031 | 2029 | | |
2032 | 2030 | | |
| |||
2036 | 2034 | | |
2037 | 2035 | | |
2038 | 2036 | | |
2039 | | - | |
| 2037 | + | |
2040 | 2038 | | |
2041 | 2039 | | |
2042 | 2040 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
582 | 582 | | |
583 | 583 | | |
584 | 584 | | |
585 | | - | |
586 | | - | |
587 | | - | |
588 | | - | |
589 | | - | |
590 | | - | |
| 585 | + | |
| 586 | + | |
591 | 587 | | |
592 | | - | |
| 588 | + | |
593 | 589 | | |
594 | 590 | | |
595 | 591 | | |
596 | | - | |
| 592 | + | |
597 | 593 | | |
598 | 594 | | |
599 | 595 | | |
| |||
| 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