Skip to content

rustdoc: re-sugar more cross-crate trait bounds - #102439

Merged
bors merged 1 commit into
rust-lang:masterfrom
fmease:rustdoc-simplify-cross-crate-trait-bounds
Oct 3, 2022
Merged

rustdoc: re-sugar more cross-crate trait bounds#102439
bors merged 1 commit into
rust-lang:masterfrom
fmease:rustdoc-simplify-cross-crate-trait-bounds

Conversation

@fmease

@fmeasefmease commented Sep 28, 2022

Copy link
Copy Markdown
Member

Previously, we would only ever re-sugar cross-crate predicates like Type: Trait, <Type as Trait>::Name == Rhs to Type: Trait<Name = Rhs> if the Type was a generic parameter like Self or T. With this PR, Type can be any type.

Most notably, this means that we now re-sugar predicates involving associated types (where Type is of the form Self::Name) which are then picked up by the pre-existing logic that re-sugars them into bounds. As a result of that, the associated type IntoIter of std's IntoIterator trait (re-exported from core) is no longer rendered as:

typeIntoIter:Iteratorwhere
<Self::IntoIterasIterator>::Item == Self::Item;

but as one would expect: type IntoIter: Iterator<Item = Self::Item>;.

Cross-crate closure bounds like F: Fn(i32) -> bool are now also rendered properly (previously, the return type (Self::Output) would not be rendered and we would show the underlying equality predicate).

Fixes#77763.
Fixes#84579.
Fixes#102142.

@rustbot label T-rustdoc A-cross-crate-reexports
r? rustdoc

@rustbotrustbot added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Sep 28, 2022
@rust-highfiverust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 28, 2022
@rustbotrustbot added A-cross-crate-reexports Area: Documentation that has been re-exported from a different crate A-rustdoc-ui Area: Rustdoc UI (generated HTML) labels Sep 28, 2022
@fmeasefmease changed the title rustdoc: simplify cross-crate trait boundsrustdoc: re-sugar cross-crate trait boundsSep 28, 2022
@rustbotrustbot removed the A-rustdoc-ui Area: Rustdoc UI (generated HTML) label Sep 28, 2022
@fmeasefmease changed the title rustdoc: re-sugar cross-crate trait boundsrustdoc: re-sugar more cross-crate trait boundsSep 28, 2022
Comment threadsrc/librustdoc/clean/simplify.rs Outdated
@GuillaumeGomez

Copy link
Copy Markdown
Member

Looks really good! Please ping me once you have some answers about the empty param_bounds.

@fmease
fmeaseforce-pushed the rustdoc-simplify-cross-crate-trait-bounds branch from f146915 to a540234CompareOctober 3, 2022 02:38
@fmease

fmease commented Oct 3, 2022

Copy link
Copy Markdown
MemberAuthor

I've changed my mind. I think it's better if we merge this PR as-is leaving the FIXME(fmease)s (whose contents I've updated in the most recent commit) for follow-up PRs. This PR is small & uncontroversial and you have already approved it. And it fixes a relatively popular issue.

On the other hand, the HRTB fix is slightly more involved (although not that much more). I am going to submit the first follow-up PR within the next few hours or so.

@GuillaumeGomez

Copy link
Copy Markdown
Member

Then let's go!

@bors r+ rollup

@bors

bors commented Oct 3, 2022

Copy link
Copy Markdown
Collaborator

📌 Commit a540234 has been approved by GuillaumeGomez

It is now in the queue for this repository.

@borsbors 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 3, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 3, 2022
…iaskrgr
Rollup of 8 pull requests
Successful merges:
- rust-lang#102439 (rustdoc: re-sugar more cross-crate trait bounds)
- rust-lang#102569 (Improve `FromStr` example)
- rust-lang#102597 (Avoid ICE in printing RPITIT type)
- rust-lang#102607 (Improve documentation of `slice::{from_ptr_range, from_ptr_range_mut}`)
- rust-lang#102613 (Fix ICE rust-lang#101739)
- rust-lang#102615 (Cleanup some error code explanations)
- rust-lang#102617 (`HirId` for `deferred_transmute_checks`)
- rust-lang#102620 (Migrate `.stab` elements style to CSS variables)
Failed merges:
r? `@ghost`
`@rustbot` modify labels: rollup
@bors
bors merged commit 2e7e17a into rust-lang:masterOct 3, 2022
@rustbotrustbot added this to the 1.66.0 milestone Oct 3, 2022
@fmease
fmease deleted the rustdoc-simplify-cross-crate-trait-bounds branch October 4, 2022 02:46
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 6, 2022
…te-hrtbs-properly, r=GuillaumeGomez
rustdoc: render more cross-crate HRTBs properly
Follow-up to rust-lang#102439.
Render the `for<>` parameter lists of cross-crate higher-rank trait bounds (in where-clauses and in `impl Trait`).
I've added a new field `bound_params` to `clean::WherePredicate::EqPredicate` (mirroring its sibling variant `BoundPredicate`). However, I had to box the existing fields since `EqPredicate` used to be the largest variant (128 bytes on 64-bit systems) and it would only have gotten bigger).
Not sure if you like that approach. As an alternative, I could pass the uncleaned `ty::Predicate` alongside the cleaned `WherePredicate` to the various re-sugaring methods (similar to what `clean::AutoTraitFinder::param_env_to_generics` does).
I haven't yet added the HTML & JSON rendering code for the newly added `bound_params` field since I am waiting for your opinion. Those two rendering code paths should actually be unreachable in practice given we re-sugar all(?) equality predicates to associated type bindings (and arbitrary equality predicates are not part of the Rust surface language at the time of this writing).
If you agree with storing `bound_params` in `EqPredicate`, I think I can use it to greatly simplify the `clean::auto_trait` module (by also using `simplify::merge_bounds`). Maybe I can do that in any case though.
`@rustbot` label T-rustdoc A-cross-crate-reexports
r? `@GuillaumeGomez`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 20, 2022
…oss-crate-gat-params, r=GuillaumeGomez
rustdoc: render bounds of cross-crate GAT params
Follow-up to rust-lang#102439.
Render the trait bounds of type parameters of cross-crate (generic) associated types.
`@rustbot` label T-rustdoc A-cross-crate-reexports
r? `@GuillaumeGomez`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 20, 2022
…oss-crate-gat-params, r=GuillaumeGomez
rustdoc: render bounds of cross-crate GAT params
Follow-up to rust-lang#102439.
Render the trait bounds of type parameters of cross-crate (generic) associated types.
``@rustbot`` label T-rustdoc A-cross-crate-reexports
r? ``@GuillaumeGomez``
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Oct 22, 2022
…oss-crate-gat-params, r=GuillaumeGomez
rustdoc: render bounds of cross-crate GAT params
Follow-up to rust-lang#102439.
Render the trait bounds of type parameters of cross-crate (generic) associated types.
```@rustbot``` label T-rustdoc A-cross-crate-reexports
r? ```@GuillaumeGomez```
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Oct 22, 2022
…oss-crate-gat-params, r=GuillaumeGomez
rustdoc: render bounds of cross-crate GAT params
Follow-up to rust-lang#102439.
Render the trait bounds of type parameters of cross-crate (generic) associated types.
````@rustbot```` label T-rustdoc A-cross-crate-reexports
r? ````@GuillaumeGomez````
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Oct 22, 2022
…oss-crate-gat-params, r=GuillaumeGomez
rustdoc: render bounds of cross-crate GAT params
Follow-up to rust-lang#102439.
Render the trait bounds of type parameters of cross-crate (generic) associated types.
`````@rustbot````` label T-rustdoc A-cross-crate-reexports
r? `````@GuillaumeGomez`````
@Urgau

Copy link
Copy Markdown
Member

I have seen some people complain on reddit and Zulip about the verbosity that is fixed by this PR. The issue is still in beta and stable, I wonder if this PR should this be backported to beta/stable ?

@GuillaumeGomez

Copy link
Copy Markdown
Member

Sounds like a good idea. I'm +1 for this.

cc @rust-lang/rustdoc

Aaron1011 pushed a commit to Aaron1011/rust that referenced this pull request Jan 6, 2023
…te-hrtbs-properly, r=GuillaumeGomez
rustdoc: render more cross-crate HRTBs properly
Follow-up to rust-lang#102439.
Render the `for<>` parameter lists of cross-crate higher-rank trait bounds (in where-clauses and in `impl Trait`).
I've added a new field `bound_params` to `clean::WherePredicate::EqPredicate` (mirroring its sibling variant `BoundPredicate`). However, I had to box the existing fields since `EqPredicate` used to be the largest variant (128 bytes on 64-bit systems) and it would only have gotten bigger).
Not sure if you like that approach. As an alternative, I could pass the uncleaned `ty::Predicate` alongside the cleaned `WherePredicate` to the various re-sugaring methods (similar to what `clean::AutoTraitFinder::param_env_to_generics` does).
I haven't yet added the HTML & JSON rendering code for the newly added `bound_params` field since I am waiting for your opinion. Those two rendering code paths should actually be unreachable in practice given we re-sugar all(?) equality predicates to associated type bindings (and arbitrary equality predicates are not part of the Rust surface language at the time of this writing).
If you agree with storing `bound_params` in `EqPredicate`, I think I can use it to greatly simplify the `clean::auto_trait` module (by also using `simplify::merge_bounds`). Maybe I can do that in any case though.
`@rustbot` label T-rustdoc A-cross-crate-reexports
r? `@GuillaumeGomez`
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-cross-crate-reexportsArea: Documentation that has been re-exported from a different crateS-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

Projects

None yet

6 participants

@fmease@GuillaumeGomez@bors@Urgau@rust-highfive@rustbot