Commit 5dbaafd
committed
Auto merge of #123340 - fmease:rustdoc-simplify-auto-trait-impl-synth, r=GuillaumeGomez
rustdoc: heavily simplify the synthesis of auto trait impls
`gd --numstat HEAD~2 HEAD src/librustdoc/clean/auto_trait.rs`
**+315 -705** 🟩🟥🟥🟥⬛
---
As outlined in issue #113015, there are currently 3[^1] large separate routines that “clean” `rustc_middle::ty` data types related to generics & predicates to rustdoc data types. Every single one has their own kinds of bugs. While I've patched a lot of bugs in each of the routines in the past, it's about time to unify them. This PR is only the first in a series. It completely **yanks** the custom “bounds cleaning” of mod `auto_trait` and reuses the routines found in mod `simplify`. As alluded to, `simplify` is also flawed but it's still more complete than `auto_trait`'s routines. [See also my review comment over at `tests/rustdoc/synthetic_auto/bounds.rs`](#123340 (comment)).
This is preparatory work for rewriting “bounds cleaning” from scratch in follow-up PRs in order to finally [fix] #113015.
Apart from that, I've eliminated all potential sources of *instability* in the rendered output.
See also #119597. I'm pretty sure this fixes #119597.
This PR does not attempt to fix [any other issues related to synthetic auto trait impls](https://github.com/rust-lang/rust/issues?q=is%3Aissue+is%3Aopen+label%3AA-synthetic-impls%20label%3AA-auto-traits).
However, it's definitely meant to be a *stepping stone* by making `auto_trait` more contributor-friendly.
---
* Replace `FxHash{Map,Set}` with `FxIndex{Map,Set}` to guarantee a stable iteration order
* Or as a perf opt, `UnordSet` (a thin wrapper around `FxHashSet`) in cases where we never iterate over the set.
* Yes, we do make use of `swap_remove` but that shouldn't matter since all the callers are deterministic. It does make the output less “predictable” but it's still better than before. Ofc, I rely on `rustc_infer` being deterministic. I hope that holds.
* Utilizing `clean::simplify` over the custom “bounds cleaning” routines wipes out the last reference to `collect_referenced_late_bound_regions` in rustdoc (`simplify` uses `bound_vars`) which was a source of instability / unpredictability (cc #116388)
* Remove the types `RegionTarget` and `RegionDeps` from `librustdoc`. They were duplicates of the identical types found in `rustc`. Just import them from `rustc`. For some reason, they were duplicated when splitting `auto_trait` in two in #49711.
* Get rid of the useless “type namespace” `AutoTraitFinder` in `librustdoc`
* The struct only held a `DocContext`, it was over-engineered
* Turn the associated functions into free ones
* Eliminates rightward drift; increases legibility
* `rustc` also contains a useless `AutoTraitFinder` struct but I plan on removing that in a follow-up PR
* Rename a bunch of methods to be way more descriptive
* Eliminate `use super::*;`
* Lead to `clean/mod.rs` accumulating a lot of unnecessary imports
* Made `auto_traits` less modular
* Eliminate a custom `TypeFolder`: We can just use the rustc helper `fold_regions` which does that for us
I plan on adding extensive documentation to `librustdoc`'s `auto_trait` in follow-up PRs.
I don't want to do that in this PR because further refactoring & bug fix PRs may alter the overall structure of `librustdoc`'s & `rustc`'s `auto_trait` modules to a great degree. I'm slowly digging into the dark details of `rustc`'s `auto_trait` module again and once I have the full picture I will be able to provide proper docs.
---
While this PR does indeed touch `rustc`'s `auto_trait` — mostly tiny refactorings — I argue this PR doesn't need any compiler reviewers next to rustdoc ones since that module falls under the purview of rustdoc — it used to be part of `librustdoc` after all (#49711).
Sorry for not having split this into more commits. If you'd like me to I can try to split it into more atomic commits retroactively. However, I don't know if that would actually make reviewing easier. I think the best way to review this might just be to place the master version of `auto_trait` on the left of your screen and the patched one on the right, not joking.
r? `@GuillaumeGomez`
[^1]: Or even 4 depending on the way you're counting.File tree
11 files changed
+452
-849
lines changed- compiler/rustc_trait_selection/src/traits
- src/librustdoc/clean
- tests/rustdoc/synthetic_auto
11 files changed
+452
-849
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
9 | 12 | | |
10 | 13 | | |
11 | 14 | | |
12 | 15 | | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
29 | | - | |
| 28 | + | |
| 29 | + | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | 38 | | |
46 | 39 | | |
47 | 40 | | |
48 | | - | |
| 41 | + | |
49 | 42 | | |
50 | 43 | | |
51 | 44 | | |
| |||
88 | 81 | | |
89 | 82 | | |
90 | 83 | | |
91 | | - | |
| 84 | + | |
92 | 85 | | |
93 | 86 | | |
94 | 87 | | |
95 | 88 | | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
| 89 | + | |
104 | 90 | | |
105 | 91 | | |
106 | 92 | | |
| |||
114 | 100 | | |
115 | 101 | | |
116 | 102 | | |
117 | | - | |
| 103 | + | |
118 | 104 | | |
119 | 105 | | |
120 | 106 | | |
| |||
239 | 225 | | |
240 | 226 | | |
241 | 227 | | |
242 | | - | |
| 228 | + | |
243 | 229 | | |
244 | 230 | | |
245 | 231 | | |
| |||
252 | 238 | | |
253 | 239 | | |
254 | 240 | | |
255 | | - | |
| 241 | + | |
256 | 242 | | |
257 | 243 | | |
258 | 244 | | |
| |||
473 | 459 | | |
474 | 460 | | |
475 | 461 | | |
476 | | - | |
477 | | - | |
478 | | - | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
479 | 465 | | |
480 | 466 | | |
481 | 467 | | |
| |||
513 | 499 | | |
514 | 500 | | |
515 | 501 | | |
516 | | - | |
517 | | - | |
518 | | - | |
| 502 | + | |
| 503 | + | |
519 | 504 | | |
520 | 505 | | |
521 | 506 | | |
522 | 507 | | |
523 | 508 | | |
524 | | - | |
| 509 | + | |
525 | 510 | | |
526 | 511 | | |
527 | | - | |
528 | 512 | | |
529 | 513 | | |
530 | 514 | | |
531 | | - | |
| 515 | + | |
532 | 516 | | |
533 | 517 | | |
534 | | - | |
535 | 518 | | |
536 | 519 | | |
537 | 520 | | |
| |||
542 | 525 | | |
543 | 526 | | |
544 | 527 | | |
545 | | - | |
| 528 | + | |
546 | 529 | | |
547 | 530 | | |
548 | | - | |
549 | 531 | | |
550 | 532 | | |
551 | 533 | | |
552 | | - | |
| 534 | + | |
553 | 535 | | |
554 | 536 | | |
555 | | - | |
556 | 537 | | |
557 | 538 | | |
558 | 539 | | |
559 | 540 | | |
560 | 541 | | |
561 | 542 | | |
562 | 543 | | |
| 544 | + | |
563 | 545 | | |
564 | 546 | | |
565 | 547 | | |
| |||
588 | 570 | | |
589 | 571 | | |
590 | 572 | | |
591 | | - | |
| 573 | + | |
592 | 574 | | |
593 | 575 | | |
594 | 576 | | |
| |||
0 commit comments