Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustdoc: fix & clean up handling of cross-crate higher-ranked parameters #116388

Conversation

fmease
Copy link
Member

@fmease fmease commented Oct 3, 2023

Preparatory work for the refactoring planned in #113015 (for correctness & maintainability).


  1. Render the higher-ranked parameters of cross-crate function pointer types (*).
  2. Replace occurrences of collect_referenced_late_bound_regions() (CRLBR) with bound_vars().
    The former is quite problematic and the use of the latter allows us to yank a lot of hacky code (†)
    as you can tell from the diff! :)
  3. Add support for cross-crate higher-ranked type parameters (#![feature(non_lifetime_binders)]).
    We were previously ICE'ing on them (see inline_cross/non_lifetime_binders.rs).

(*): Extracted from test inline_cross/fn-type.rs:

- fn(_: &'z fn(_: &'b str), _: &'a ()) -> &'a ()
+ for<'z, 'a, '_unused> fn(_: &'z for<'b> fn(_: &'b str), _: &'a ()) -> &'a ()

(†): It returns an FxHashSet which isn't predictable or stable wrt. source code (.rmeta) changes. To elaborate, the ordering of late-bound regions doesn't necessarily reflect the ordering found in the source code. It does seem to be stable across compilations but modifying the source code of the to-be-documented crates (like adding or renaming items) may result in a different order:

Example

Let's assume that we're documenting the cross-crate re-export of produce from the code below. On master, rustdoc would render the list of binders as for<'x, 'y, 'z>. However, once you add back the functions al, it would be rendered as for<'z, 'y, 'x> (reverse order)! Results may vary. bound_vars() fixes this as it returns them in source order.

// pub fn a() {}
// pub fn b() {}
// pub fn c() {}
// pub fn d() {}
// pub fn e() {}
// pub fn f() {}
// pub fn g() {}
// pub fn h() {}
// pub fn i() {}
// pub fn j() {}
// pub fn k() {}
// pub fn l() {}

pub fn produce() -> impl for<'x, 'y, 'z> Trait<'z, 'y, 'x> {}

pub trait Trait<'a, 'b, 'c> {}

impl Trait<'_, '_, '_> for () {}

Further, as the name suggests, CRLBR only collects referenced regions and thus we drop unused binders. bound_vars() contains unused binders on the other hand. Let's stay closer to the source where possible and keep unused binders.

Lastly, using bound_vars() allows us to get rid of

  • the deduplication and alphabetical sorting hack in simplify.rs
  • the weird field bound_params on EqPredicate

both of which were introduced by me in #102707 back when I didn't know better.

To illustrate, let's look at the cross-crate bound T: for<'a, 'b> Trait<A<'a> = (), B<'b> = ()>.

  • With CRLBR + EqPredicate.bound_params, before bound simplification we would have the bounds T: Trait, for<'a> <T as Trait>::A<'a> == () and for<'b> <T as Trait>::B<'b> == () which required us to merge for<>, for<'a> and for<'b> into for<'a, 'b> in a deterministic predictable manner and without introducing duplicate binders.
  • With bound_vars(), we now have the bounds for<'a, b> T: Trait, <T as Trait>::A<'a> == () and <T as Trait>::B<'b> == () before bound simplification similar to rustc itself. This obviously no longer requires any funny merging of for<>s. On top of that for<'a, 'b> is guaranteed to be in source order.

@rustbot
Copy link
Collaborator

rustbot commented Oct 3, 2023

r? @notriddle

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added A-rustdoc-json Area: Rustdoc JSON backend S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Oct 3, 2023
@rustbot
Copy link
Collaborator

rustbot commented Oct 3, 2023

Some changes occurred in src/librustdoc/clean/types.rs

cc @camelid

@fmease fmease added A-cross-crate-reexports Area: Documentation that has been re-exported from a different crate and removed A-rustdoc-json Area: Rustdoc JSON backend labels Oct 3, 2023
Comment on lines +3093 to +3095
fn clean_bound_vars<'tcx>(
bound_vars: &'tcx ty::List<ty::BoundVariableKind>,
) -> Vec<GenericParamDef> {
Copy link
Member Author

@fmease fmease Oct 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Theoretically, I could make this generic by letting it take a <T> bound_ty: ty::Binder<'tcx, T> instead but I've decided against it for simplicity and to avoid code size explosion due to excessive monomorphization. I could use a non-generic inner function though, if you'd like.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy with this function not being generic. It wouldn't save very much code at the call site if it was.

@fmease fmease added the C-cleanup Category: PRs that clean code up or issues documenting cleanup. label Oct 3, 2023
BareFunction(Box::new(BareFunctionDecl {
unsafety: sig.unsafety(),
generic_params: Vec::new(),
generic_params,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change allows us to render the for<> parameter list of cross-crate fn ptr tys.

ty::BrNamed(_, name) if br.is_named() => Some(GenericParamDef::lifetime(name)),
_ => None,
})
.collect();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If nothing else, I'm glad to see all this duplicate code factored out into a function. ❤️

Comment on lines +3093 to +3095
fn clean_bound_vars<'tcx>(
bound_vars: &'tcx ty::List<ty::BoundVariableKind>,
) -> Vec<GenericParamDef> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy with this function not being generic. It wouldn't save very much code at the call site if it was.

@@ -2109,9 +2071,11 @@ pub(crate) fn clean_middle_ty<'tcx>(
// FIXME: should we merge the outer and inner binders somehow?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does anybody know what kind of code would motivate fixing this? Is it actually possible to make rustdoc misrender something because the outer and inner binders aren't being merged?

Copy link
Member Author

@fmease fmease Oct 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not super familiar with some of the details surrounding bound vars yet. I can't tell you all possible cases where the type and the signature have bound vars at the same time.

I can give you one example though which rustdoc renders just fine:

pub fn f(_: impl for<'a> Trait<for<'b> fn(&'a (), &'b ())>) {  }
pub trait Trait<T> {}

Here, bound_ty.bound_vars() is ['a] and sig.bound_vars() is ['b]. It would be incorrect to concatenate ['a] and ['b]. We don't want to render for<'a> … for<'a, 'b> fn(…).

In this case, the bound_ty.bound_vars() is ['a] because clean_poly_trait_ref_with_bindings passes this list of bound vars down to external_path to … to ty_args_to_args which calls clean_middle_ty. I'm not sure if that's the intended usage of map_bound but I guess it is since oli-obk implemented that as far as I know.
bound_ty.skip_binder() and just using sig.bound_vars() should therefore be fine.

Copy link
Member Author

@fmease fmease Oct 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my limited understanding, I disagree with the FIXME, it would be super odd to merge different binder lists, rustc does it like one or two times in exceptional cases. There can be a semantic difference between for<'a> … for<'b> … and for<'a, 'b> … and rustc needs to shift the de Bruijn indices and the var indices for correctness after merging such lists.

A few months ago, I chatted a bit with compiler-errors about ty::Binder<_> and bound vars in rustdoc and from what I've learned rustdoc (still) doesn't properly track bound vars. This was relevant for #112463 where we don't have enough information to be able to deal with (escaping) late bound vars. I haven't understood everything yet and thus my explanation sucks.

I'm pretty sure from what I've learned so far, proper bound var handling would prevent ICEs in rustdoc like in PR #108503 (which you're acquainted with) and probably other ones like https://github.com/rust-lang/rust/issues?q=is%3Aissue+is%3Aopen+label%3AT-rustdoc%20label%3AI-ICE%20label%3AA-auto-traits%20label%3AA-synthetic-impls.

@notriddle
Copy link
Contributor

That makes sense.

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Oct 4, 2023

📌 Commit ace85f0 has been approved by notriddle

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 4, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 4, 2023
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#115961 (Replace 'mutex' with 'lock' in RwLock documentation)
 - rust-lang#116146 (Clarify `arg` and `args` documentation)
 - rust-lang#116363 (Adapt `todo!` documentation to mention displaying custom values)
 - rust-lang#116365 (bootstrap: make copying linker binaries conditional)
 - rust-lang#116388 (rustdoc: fix & clean up handling of cross-crate higher-ranked parameters)
 - rust-lang#116393 (Emit feature gate *warning* for `auto` traits pre-expansion)
 - rust-lang#116395 (Mark myself as vacation or whatever)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 3e29363 into rust-lang:master Oct 4, 2023
11 checks passed
@rustbot rustbot added this to the 1.75.0 milestone Oct 4, 2023
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Oct 4, 2023
Rollup merge of rust-lang#116388 - fmease:rustdoc-fix-n-clean-up-x-crate-higher-ranked-params, r=notriddle

rustdoc: fix & clean up handling of cross-crate higher-ranked parameters

Preparatory work for the refactoring planned in rust-lang#113015 (for correctness & maintainability).

---

1. Render the higher-ranked parameters of cross-crate function pointer types **(*)**.
2. Replace occurrences of `collect_referenced_late_bound_regions()` (CRLBR) with `bound_vars()`.
  The former is quite problematic and the use of the latter allows us to yank a lot of hacky code **(†)**
  as you can tell from the diff! :)
3. Add support for cross-crate higher-ranked types (`#![feature(non_lifetime_binders)]`).
  We were previously ICE'ing on them (see `inline_cross/non_lifetime_binders.rs`).

---

**(*)**: Extracted from test `inline_cross/fn-type.rs`:

```diff
- fn(_: &'z fn(_: &'b str), _: &'a ()) -> &'a ()
+ for<'z, 'a, '_unused> fn(_: &'z for<'b> fn(_: &'b str), _: &'a ()) -> &'a ()
```

**(†)**: It returns an `FxHashSet` which isn't *predictable* or *stable* wrt. source code (`.rmeta`) changes. To elaborate, the ordering of late-bound regions doesn't necessarily reflect the ordering found in the source code. It does seem to be stable across compilations but modifying the source code of the to-be-documented crates (like adding or renaming items) may result in a different order:

<details><summary>Example</summary>

Let's assume that we're documenting the cross-crate re-export of `produce` from the code below. On `master`, rustdoc would render the list of binders as `for<'x, 'y, 'z>`. However, once you add back the functions `a`–`l`, it would be rendered as `for<'z, 'y, 'x>` (reverse order)! Results may vary. `bound_vars()` fixes this as it returns them in source order.

```rs
// pub fn a() {}
// pub fn b() {}
// pub fn c() {}
// pub fn d() {}
// pub fn e() {}
// pub fn f() {}
// pub fn g() {}
// pub fn h() {}
// pub fn i() {}
// pub fn j() {}
// pub fn k() {}
// pub fn l() {}

pub fn produce() -> impl for<'x, 'y, 'z> Trait<'z, 'y, 'x> {}

pub trait Trait<'a, 'b, 'c> {}

impl Trait<'_, '_, '_> for () {}
```

</details>

Further, as the name suggests, CRLBR only collects *referenced* regions and thus we drop unused binders. `bound_vars()` contains unused binders on the other hand. Let's stay closer to the source where possible and keep unused binders.

Lastly, using `bound_vars()` allows us to get rid of

* the deduplication and alphabetical sorting hack in `simplify.rs`
* the weird field `bound_params` on `EqPredicate`

both of which were introduced by me in rust-lang#102707 back when I didn't know better.

To illustrate, let's look at the cross-crate bound `T: for<'a, 'b> Trait<A<'a> = (), B<'b> = ()>`.

* With CRLBR + `EqPredicate.bound_params`, *before* bounds simplification we would have the bounds `T: Trait`, `for<'a> <T as Trait>::A<'a> == ()` and `for<'b> <T as Trait>::B<'b> == ()` which required us to merge `for<>`, `for<'a>` and `for<'b>` into `for<'a, 'b>` in a deterministic manner and without introducing duplicate binders.
* With `bound_vars()`, we now have the bounds `for<'a, b> T: Trait`, `<T as Trait>::A<'a> == ()` and `<T as Trait>::B<'b> == ()` before bound simplification similar to rustc itself. This obviously no longer requires any funny merging of `for<>`s. On top of that `for<'a, 'b>` is guaranteed to be in source order.
@fmease fmease deleted the rustdoc-fix-n-clean-up-x-crate-higher-ranked-params branch October 4, 2023 07:27
bors-ferrocene bot added a commit to ferrocene/ferrocene that referenced this pull request Oct 5, 2023
23: Fix divergence from upstream `master` r=tshepang a=pvdrz

* rust-lang/rust#116381
* rust-lang/rust#116360
* rust-lang/rust#116353
* rust-lang/rust#116406
* rust-lang/rust#116408
  * rust-lang/rust#116395
  * rust-lang/rust#116393
  * rust-lang/rust#116388
  * rust-lang/rust#116365
  * rust-lang/rust#116363
  * rust-lang/rust#116146
  * rust-lang/rust#115961
* rust-lang/rust#116386
* rust-lang/rust#116367
* rust-lang/rust#105394
* rust-lang/rust#115301
* rust-lang/rust#116384
  * rust-lang/rust#116379
  * rust-lang/rust#116328
  * rust-lang/rust#116282
  * rust-lang/rust#116261
  * rust-lang/rust#114654
* rust-lang/rust#116376
  * rust-lang/rust#116374
  * rust-lang/rust#116371
  * rust-lang/rust#116358
  * rust-lang/rust#116210
  * rust-lang/rust#115863
* rust-lang/rust#115025
* rust-lang/rust#116372
  * rust-lang/rust#116361
  * rust-lang/rust#116355
  * rust-lang/rust#116351
  * rust-lang/rust#116158
  * rust-lang/rust#115726
  * rust-lang/rust#113053
* rust-lang/rust#116083
* rust-lang/rust#102099
* rust-lang/rust#116356
  * rust-lang/rust#116350
  * rust-lang/rust#116349
  * rust-lang/rust#116289
  * rust-lang/rust#114454
  * rust-lang/rust#114453
* rust-lang/rust#116331
* rust-lang/rust#116346
  * rust-lang/rust#116340
  * rust-lang/rust#116326
  * rust-lang/rust#116313
* rust-lang/rust#116276
* rust-lang/rust#115898
* rust-lang/rust#116325
* rust-lang/rust#116317
* rust-lang/rust#116207
* rust-lang/rust#116281
* rust-lang/rust#116304
* rust-lang/rust#116259
* rust-lang/rust#116228
* rust-lang/rust#116224
* rust-lang/rust#115554
* rust-lang/rust#116311
  * rust-lang/rust#116299
  * rust-lang/rust#116295
  * rust-lang/rust#116292
* rust-lang/rust#116307
* rust-lang/rust#115670
* rust-lang/rust#116225
* rust-lang/rust#116302
* rust-lang/rust#116108
* rust-lang/rust#116160
* rust-lang/rust#116157
* rust-lang/rust#116127
* rust-lang/rust#116286
* rust-lang/rust#116254
* rust-lang/rust#116195
* rust-lang/rust#116280
* rust-lang/rust#115933
* rust-lang/rust#115546
* rust-lang/rust#115368
* rust-lang/rust#116275
  * rust-lang/rust#116263
  * rust-lang/rust#116241
  * rust-lang/rust#116216
  * rust-lang/rust#116030
  * rust-lang/rust#116024
  * rust-lang/rust#112123
* rust-lang/rust#113301
* rust-lang/rust#113797
* rust-lang/rust#115759
* rust-lang/rust#116260
  * rust-lang/rust#116253
  * rust-lang/rust#116245
  * rust-lang/rust#116239
  * rust-lang/rust#116234
  * rust-lang/rust#116231
  * rust-lang/rust#116201
  * rust-lang/rust#116133
* rust-lang/rust#116176
* rust-lang/rust#116089
* rust-lang/rust#115986



Co-authored-by: ouz-a <ouz.agz@gmail.com>
Co-authored-by: Jakub Beránek <berykubik@gmail.com>
Co-authored-by: Federico Stra <stra.federico@gmail.com>
Co-authored-by: bohan <bohan-zhang@foxmail.com>
Co-authored-by: Jason Newcomb <jsnewcomb@pm.me>
Co-authored-by: Ralf Jung <post@ralfj.de>
Co-authored-by: bors <bors@rust-lang.org>
Co-authored-by: Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de>
bors-ferrocene bot added a commit to ferrocene/ferrocene that referenced this pull request Oct 6, 2023
23: Fix divergence from upstream `master` r=tshepang a=pvdrz

* rust-lang/rust#116483
  * rust-lang/rust#116475
  * rust-lang/rust#116329
  * rust-lang/rust#116198
  * rust-lang/rust#115588
  * rust-lang/rust#115522
  * rust-lang/rust#115454
* rust-lang/rust#111595
* rust-lang/rust#116018
* rust-lang/rust#116472
  * rust-lang/rust#116469
  * rust-lang/rust#116421
* rust-lang/rust#116463
* rust-lang/rust#101150
* rust-lang/rust#116269
* rust-lang/rust#116417
* rust-lang/rust#116455
  * rust-lang/rust#116452
  * rust-lang/rust#116428
  * rust-lang/rust#116415
  * rust-lang/rust#116288
  * rust-lang/rust#116220
* rust-lang/rust#103046
* rust-lang/rust#114042
* rust-lang/rust#104153
* rust-lang/rust#116427
* rust-lang/rust#116443
  * rust-lang/rust#116432
  * rust-lang/rust#116431
  * rust-lang/rust#116429
  * rust-lang/rust#116296
  * rust-lang/rust#116223
* rust-lang/rust#116273
* rust-lang/rust#116184
* rust-lang/rust#116370
* rust-lang/rust#114417
* rust-lang/rust#115200
* rust-lang/rust#116413
* rust-lang/rust#116381
* rust-lang/rust#116360
* rust-lang/rust#116353
* rust-lang/rust#116406
* rust-lang/rust#116408
  * rust-lang/rust#116395
  * rust-lang/rust#116393
  * rust-lang/rust#116388
  * rust-lang/rust#116365
  * rust-lang/rust#116363
  * rust-lang/rust#116146
  * rust-lang/rust#115961
* rust-lang/rust#116386
* rust-lang/rust#116367
* rust-lang/rust#105394
* rust-lang/rust#115301
* rust-lang/rust#116384
  * rust-lang/rust#116379
  * rust-lang/rust#116328
  * rust-lang/rust#116282
  * rust-lang/rust#116261
  * rust-lang/rust#114654
* rust-lang/rust#116376
  * rust-lang/rust#116374
  * rust-lang/rust#116371
  * rust-lang/rust#116358
  * rust-lang/rust#116210
  * rust-lang/rust#115863
* rust-lang/rust#115025
* rust-lang/rust#116372
  * rust-lang/rust#116361
  * rust-lang/rust#116355
  * rust-lang/rust#116351
  * rust-lang/rust#116158
  * rust-lang/rust#115726
  * rust-lang/rust#113053
* rust-lang/rust#116083
* rust-lang/rust#102099
* rust-lang/rust#116356
  * rust-lang/rust#116350
  * rust-lang/rust#116349
  * rust-lang/rust#116289
  * rust-lang/rust#114454
  * rust-lang/rust#114453
* rust-lang/rust#116331
* rust-lang/rust#116346
  * rust-lang/rust#116340
  * rust-lang/rust#116326
  * rust-lang/rust#116313
* rust-lang/rust#116276
* rust-lang/rust#115898
* rust-lang/rust#116325
* rust-lang/rust#116317
* rust-lang/rust#116207
* rust-lang/rust#116281
* rust-lang/rust#116304
* rust-lang/rust#116259
* rust-lang/rust#116228
* rust-lang/rust#116224
* rust-lang/rust#115554
* rust-lang/rust#116311
  * rust-lang/rust#116299
  * rust-lang/rust#116295
  * rust-lang/rust#116292
* rust-lang/rust#116307
* rust-lang/rust#115670
* rust-lang/rust#116225
* rust-lang/rust#116302
* rust-lang/rust#116108
* rust-lang/rust#116160
* rust-lang/rust#116157
* rust-lang/rust#116127
* rust-lang/rust#116286
* rust-lang/rust#116254
* rust-lang/rust#116195
* rust-lang/rust#116280
* rust-lang/rust#115933
* rust-lang/rust#115546
* rust-lang/rust#115368
* rust-lang/rust#116275
  * rust-lang/rust#116263
  * rust-lang/rust#116241
  * rust-lang/rust#116216
  * rust-lang/rust#116030
  * rust-lang/rust#116024
  * rust-lang/rust#112123
* rust-lang/rust#113301
* rust-lang/rust#113797
* rust-lang/rust#115759
* rust-lang/rust#116260
  * rust-lang/rust#116253
  * rust-lang/rust#116245
  * rust-lang/rust#116239
  * rust-lang/rust#116234
  * rust-lang/rust#116231
  * rust-lang/rust#116201
  * rust-lang/rust#116133
* rust-lang/rust#116176
* rust-lang/rust#116089
* rust-lang/rust#115986

Co-authored-by: ouz-a <ouz.agz@gmail.com>
Co-authored-by: bors <bors@rust-lang.org>
Co-authored-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Co-authored-by: linkmauve <linkmauve@linkmauve.fr>
Co-authored-by: onur-ozkan <work@onurozkan.dev>
Co-authored-by: asquared31415 <34665709+asquared31415@users.noreply.github.com>
Co-authored-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
Co-authored-by: Ralf Jung <post@ralfj.de>
Co-authored-by: Nadrieril <nadrieril+git@gmail.com>
Co-authored-by: Raekye <Raekye@users.noreply.github.com>
Co-authored-by: Mark Rousskov <mark.simulacrum@gmail.com>
Co-authored-by: Zalathar <Zalathar@users.noreply.github.com>
bors-ferrocene bot added a commit to ferrocene/ferrocene that referenced this pull request Oct 9, 2023
23: Fix divergence from upstream `master` r=pietroalbini a=pvdrz

* rust-lang/rust#116483
  * rust-lang/rust#116475
  * rust-lang/rust#116329
  * rust-lang/rust#116198
  * rust-lang/rust#115588
  * rust-lang/rust#115522
  * rust-lang/rust#115454
* rust-lang/rust#111595
* rust-lang/rust#116018
* rust-lang/rust#116472
  * rust-lang/rust#116469
  * rust-lang/rust#116421
* rust-lang/rust#116463
* rust-lang/rust#101150
* rust-lang/rust#116269
* rust-lang/rust#116417
* rust-lang/rust#116455
  * rust-lang/rust#116452
  * rust-lang/rust#116428
  * rust-lang/rust#116415
  * rust-lang/rust#116288
  * rust-lang/rust#116220
* rust-lang/rust#103046
* rust-lang/rust#114042
* rust-lang/rust#104153
* rust-lang/rust#116427
* rust-lang/rust#116443
  * rust-lang/rust#116432
  * rust-lang/rust#116431
  * rust-lang/rust#116429
  * rust-lang/rust#116296
  * rust-lang/rust#116223
* rust-lang/rust#116273
* rust-lang/rust#116184
* rust-lang/rust#116370
* rust-lang/rust#114417
* rust-lang/rust#115200
* rust-lang/rust#116413
* rust-lang/rust#116381
* rust-lang/rust#116360
* rust-lang/rust#116353
* rust-lang/rust#116406
* rust-lang/rust#116408
  * rust-lang/rust#116395
  * rust-lang/rust#116393
  * rust-lang/rust#116388
  * rust-lang/rust#116365
  * rust-lang/rust#116363
  * rust-lang/rust#116146
  * rust-lang/rust#115961
* rust-lang/rust#116386
* rust-lang/rust#116367
* rust-lang/rust#105394
* rust-lang/rust#115301
* rust-lang/rust#116384
  * rust-lang/rust#116379
  * rust-lang/rust#116328
  * rust-lang/rust#116282
  * rust-lang/rust#116261
  * rust-lang/rust#114654
* rust-lang/rust#116376
  * rust-lang/rust#116374
  * rust-lang/rust#116371
  * rust-lang/rust#116358
  * rust-lang/rust#116210
  * rust-lang/rust#115863
* rust-lang/rust#115025
* rust-lang/rust#116372
  * rust-lang/rust#116361
  * rust-lang/rust#116355
  * rust-lang/rust#116351
  * rust-lang/rust#116158
  * rust-lang/rust#115726
  * rust-lang/rust#113053
* rust-lang/rust#116083
* rust-lang/rust#102099
* rust-lang/rust#116356
  * rust-lang/rust#116350
  * rust-lang/rust#116349
  * rust-lang/rust#116289
  * rust-lang/rust#114454
  * rust-lang/rust#114453
* rust-lang/rust#116331
* rust-lang/rust#116346
  * rust-lang/rust#116340
  * rust-lang/rust#116326
  * rust-lang/rust#116313
* rust-lang/rust#116276
* rust-lang/rust#115898
* rust-lang/rust#116325
* rust-lang/rust#116317
* rust-lang/rust#116207
* rust-lang/rust#116281
* rust-lang/rust#116304
* rust-lang/rust#116259
* rust-lang/rust#116228
* rust-lang/rust#116224
* rust-lang/rust#115554
* rust-lang/rust#116311
  * rust-lang/rust#116299
  * rust-lang/rust#116295
  * rust-lang/rust#116292
* rust-lang/rust#116307
* rust-lang/rust#115670
* rust-lang/rust#116225
* rust-lang/rust#116302
* rust-lang/rust#116108
* rust-lang/rust#116160
* rust-lang/rust#116157
* rust-lang/rust#116127
* rust-lang/rust#116286
* rust-lang/rust#116254
* rust-lang/rust#116195
* rust-lang/rust#116280
* rust-lang/rust#115933
* rust-lang/rust#115546
* rust-lang/rust#115368
* rust-lang/rust#116275
  * rust-lang/rust#116263
  * rust-lang/rust#116241
  * rust-lang/rust#116216
  * rust-lang/rust#116030
  * rust-lang/rust#116024
  * rust-lang/rust#112123
* rust-lang/rust#113301
* rust-lang/rust#113797
* rust-lang/rust#115759
* rust-lang/rust#116260
  * rust-lang/rust#116253
  * rust-lang/rust#116245
  * rust-lang/rust#116239
  * rust-lang/rust#116234
  * rust-lang/rust#116231
  * rust-lang/rust#116201
  * rust-lang/rust#116133
* rust-lang/rust#116176
* rust-lang/rust#116089
* rust-lang/rust#115986

Co-authored-by: bors <bors@rust-lang.org>
Co-authored-by: ouz-a <ouz.agz@gmail.com>
Co-authored-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Co-authored-by: linkmauve <linkmauve@linkmauve.fr>
Co-authored-by: onur-ozkan <work@onurozkan.dev>
Co-authored-by: asquared31415 <34665709+asquared31415@users.noreply.github.com>
Co-authored-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
Co-authored-by: Ralf Jung <post@ralfj.de>
Co-authored-by: Nadrieril <nadrieril+git@gmail.com>
Co-authored-by: Raekye <Raekye@users.noreply.github.com>
Co-authored-by: Mark Rousskov <mark.simulacrum@gmail.com>
Co-authored-by: Zalathar <Zalathar@users.noreply.github.com>
bors-ferrocene bot added a commit to ferrocene/ferrocene that referenced this pull request Oct 9, 2023
23: Fix divergence from upstream `master` r=Dajamante a=pvdrz

* rust-lang/rust#116483
  * rust-lang/rust#116475
  * rust-lang/rust#116329
  * rust-lang/rust#116198
  * rust-lang/rust#115588
  * rust-lang/rust#115522
  * rust-lang/rust#115454
* rust-lang/rust#111595
* rust-lang/rust#116018
* rust-lang/rust#116472
  * rust-lang/rust#116469
  * rust-lang/rust#116421
* rust-lang/rust#116463
* rust-lang/rust#101150
* rust-lang/rust#116269
* rust-lang/rust#116417
* rust-lang/rust#116455
  * rust-lang/rust#116452
  * rust-lang/rust#116428
  * rust-lang/rust#116415
  * rust-lang/rust#116288
  * rust-lang/rust#116220
* rust-lang/rust#103046
* rust-lang/rust#114042
* rust-lang/rust#104153
* rust-lang/rust#116427
* rust-lang/rust#116443
  * rust-lang/rust#116432
  * rust-lang/rust#116431
  * rust-lang/rust#116429
  * rust-lang/rust#116296
  * rust-lang/rust#116223
* rust-lang/rust#116273
* rust-lang/rust#116184
* rust-lang/rust#116370
* rust-lang/rust#114417
* rust-lang/rust#115200
* rust-lang/rust#116413
* rust-lang/rust#116381
* rust-lang/rust#116360
* rust-lang/rust#116353
* rust-lang/rust#116406
* rust-lang/rust#116408
  * rust-lang/rust#116395
  * rust-lang/rust#116393
  * rust-lang/rust#116388
  * rust-lang/rust#116365
  * rust-lang/rust#116363
  * rust-lang/rust#116146
  * rust-lang/rust#115961
* rust-lang/rust#116386
* rust-lang/rust#116367
* rust-lang/rust#105394
* rust-lang/rust#115301
* rust-lang/rust#116384
  * rust-lang/rust#116379
  * rust-lang/rust#116328
  * rust-lang/rust#116282
  * rust-lang/rust#116261
  * rust-lang/rust#114654
* rust-lang/rust#116376
  * rust-lang/rust#116374
  * rust-lang/rust#116371
  * rust-lang/rust#116358
  * rust-lang/rust#116210
  * rust-lang/rust#115863
* rust-lang/rust#115025
* rust-lang/rust#116372
  * rust-lang/rust#116361
  * rust-lang/rust#116355
  * rust-lang/rust#116351
  * rust-lang/rust#116158
  * rust-lang/rust#115726
  * rust-lang/rust#113053
* rust-lang/rust#116083
* rust-lang/rust#102099
* rust-lang/rust#116356
  * rust-lang/rust#116350
  * rust-lang/rust#116349
  * rust-lang/rust#116289
  * rust-lang/rust#114454
  * rust-lang/rust#114453
* rust-lang/rust#116331
* rust-lang/rust#116346
  * rust-lang/rust#116340
  * rust-lang/rust#116326
  * rust-lang/rust#116313
* rust-lang/rust#116276
* rust-lang/rust#115898
* rust-lang/rust#116325
* rust-lang/rust#116317
* rust-lang/rust#116207
* rust-lang/rust#116281
* rust-lang/rust#116304
* rust-lang/rust#116259
* rust-lang/rust#116228
* rust-lang/rust#116224
* rust-lang/rust#115554
* rust-lang/rust#116311
  * rust-lang/rust#116299
  * rust-lang/rust#116295
  * rust-lang/rust#116292
* rust-lang/rust#116307
* rust-lang/rust#115670
* rust-lang/rust#116225
* rust-lang/rust#116302
* rust-lang/rust#116108
* rust-lang/rust#116160
* rust-lang/rust#116157
* rust-lang/rust#116127
* rust-lang/rust#116286
* rust-lang/rust#116254
* rust-lang/rust#116195
* rust-lang/rust#116280
* rust-lang/rust#115933
* rust-lang/rust#115546
* rust-lang/rust#115368
* rust-lang/rust#116275
  * rust-lang/rust#116263
  * rust-lang/rust#116241
  * rust-lang/rust#116216
  * rust-lang/rust#116030
  * rust-lang/rust#116024
  * rust-lang/rust#112123
* rust-lang/rust#113301
* rust-lang/rust#113797
* rust-lang/rust#115759
* rust-lang/rust#116260
  * rust-lang/rust#116253
  * rust-lang/rust#116245
  * rust-lang/rust#116239
  * rust-lang/rust#116234
  * rust-lang/rust#116231
  * rust-lang/rust#116201
  * rust-lang/rust#116133
* rust-lang/rust#116176
* rust-lang/rust#116089
* rust-lang/rust#115986

35: Automated pull from `rust-lang/libc` r=pietroalbini a=github-actions[bot]

This PR pulls the following changes from the [`rust-lang/libc`](https://github.com/rust-lang/libc) repository:

* rust-lang/libc#3335
* rust-lang/libc#3373
* rust-lang/libc#3360
* rust-lang/libc#3374
* rust-lang/libc#3375
* rust-lang/libc#3376
* rust-lang/libc#3377


Co-authored-by: ouz-a <ouz.agz@gmail.com>
Co-authored-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Co-authored-by: bors <bors@rust-lang.org>
Co-authored-by: linkmauve <linkmauve@linkmauve.fr>
Co-authored-by: onur-ozkan <work@onurozkan.dev>
Co-authored-by: asquared31415 <34665709+asquared31415@users.noreply.github.com>
Co-authored-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
Co-authored-by: Ralf Jung <post@ralfj.de>
Co-authored-by: Nadrieril <nadrieril+git@gmail.com>
Co-authored-by: Raekye <Raekye@users.noreply.github.com>
Co-authored-by: Mark Rousskov <mark.simulacrum@gmail.com>
Co-authored-by: Zalathar <Zalathar@users.noreply.github.com>
Co-authored-by: Nikolay Arhipov <nikolajs.arhipovs@gmail.com>
Co-authored-by: Brian Cain <bcain@quicinc.com>
Co-authored-by: Steve Lau <stevelauc@outlook.com>
Co-authored-by: David CARLIER <devnexen@gmail.com>
Co-authored-by: Louis Dupré Bertoni <louisdb@lespetitspedestres.org>
Co-authored-by: Taiki Endo <te316e89@gmail.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 2, 2024
…mpl-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 rust-lang#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`](rust-lang#123340 (comment)).

This is preparatory work for rewriting “bounds cleaning” from scratch in follow-up PRs in order to finally [fix] rust-lang#113015.

Apart from that, I've eliminated all potential sources of *instability* in the rendered output.
See also rust-lang#119597. I'm pretty sure this fixes rust-lang#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 rust-lang#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 rust-lang#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 (rust-lang#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cross-crate-reexports Area: Documentation that has been re-exported from a different crate C-cleanup Category: PRs that clean code up or issues documenting cleanup. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants