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: Preserve rendering of macro_rules matchers when possible #92334

Merged
merged 3 commits into from Jan 14, 2022

Conversation

dtolnay
Copy link
Member

@dtolnay dtolnay commented Dec 27, 2021

Fixes #92331. This approach restores the behavior prior to #86282 if the matcher token held by the compiler and the matcher token found in the source code are identical TokenTrees. Thus #86208 remains fixed, but without regressing formatting for the vast majority of macros which are not macro-generated.

@rustbot rustbot added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Dec 27, 2021
@rust-highfive
Copy link
Collaborator

r? @GuillaumeGomez

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 27, 2021
@dtolnay
Copy link
Member Author

dtolnay commented Dec 27, 2021

r? @jyn514 @camelid

@dtolnay dtolnay requested a review from camelid December 27, 2021 22:25
@jyn514 jyn514 assigned camelid and unassigned jyn514 Dec 27, 2021
@jyn514
Copy link
Member

jyn514 commented Dec 27, 2021

I'm on vacation, @camelid is a good reviewer for this.

@GuillaumeGomez
Copy link
Member

Looks good to me, thanks! Since @camelid wrote the original fix, I'll let them approve it to ensure I didn't miss something.

src/librustdoc/clean/utils.rs Show resolved Hide resolved
src/librustdoc/clean/utils.rs Outdated Show resolved Hide resolved
@camelid
Copy link
Member

camelid commented Dec 28, 2021

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Dec 28, 2021
@bors
Copy link
Contributor

bors commented Dec 28, 2021

⌛ Trying commit 336c85a with merge fb688212cf86e824584013f4782762968dac2c29...

@camelid camelid added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 28, 2021
@dtolnay dtolnay removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Dec 29, 2021
@camelid
Copy link
Member

camelid commented Jan 1, 2022

Looks like the bors try run was cancelled by the new commits.

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@bors
Copy link
Contributor

bors commented Jan 1, 2022

⌛ Trying commit 0f8415b with merge 37e033d1f348ba89031ea970f17f2923147403f1...

@bors
Copy link
Contributor

bors commented Jan 1, 2022

☀️ Try build successful - checks-actions
Build commit: 37e033d1f348ba89031ea970f17f2923147403f1 (37e033d1f348ba89031ea970f17f2923147403f1)

@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 Jan 8, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 9, 2022
…uillaumeGomez

rustdoc: Preserve rendering of macro_rules matchers when possible

Fixes rust-lang#92331. This approach restores the behavior prior to rust-lang#86282 **if** the matcher token held by the compiler **and** the matcher token found in the source code are identical TokenTrees. Thus rust-lang#86208 remains fixed, but without regressing formatting for the vast majority of macros which are not macro-generated.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 10, 2022
…uillaumeGomez

rustdoc: Preserve rendering of macro_rules matchers when possible

Fixes rust-lang#92331. This approach restores the behavior prior to rust-lang#86282 **if** the matcher token held by the compiler **and** the matcher token found in the source code are identical TokenTrees. Thus rust-lang#86208 remains fixed, but without regressing formatting for the vast majority of macros which are not macro-generated.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 10, 2022
…uillaumeGomez

rustdoc: Preserve rendering of macro_rules matchers when possible

Fixes rust-lang#92331. This approach restores the behavior prior to rust-lang#86282 **if** the matcher token held by the compiler **and** the matcher token found in the source code are identical TokenTrees. Thus rust-lang#86208 remains fixed, but without regressing formatting for the vast majority of macros which are not macro-generated.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 12, 2022
…uillaumeGomez

rustdoc: Preserve rendering of macro_rules matchers when possible

Fixes rust-lang#92331. This approach restores the behavior prior to rust-lang#86282 **if** the matcher token held by the compiler **and** the matcher token found in the source code are identical TokenTrees. Thus rust-lang#86208 remains fixed, but without regressing formatting for the vast majority of macros which are not macro-generated.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 13, 2022
…uillaumeGomez

rustdoc: Preserve rendering of macro_rules matchers when possible

Fixes rust-lang#92331. This approach restores the behavior prior to rust-lang#86282 **if** the matcher token held by the compiler **and** the matcher token found in the source code are identical TokenTrees. Thus rust-lang#86208 remains fixed, but without regressing formatting for the vast majority of macros which are not macro-generated.
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 14, 2022
…askrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#90001 (Make rlib metadata strip works with MIPSr6 architecture)
 - rust-lang#91687 (rustdoc: do not emit tuple variant fields if none are documented)
 - rust-lang#91938 (Add `std::error::Report` type)
 - rust-lang#92006 (Welcome opaque types into the fold)
 - rust-lang#92142 ([code coverage] Fix missing dead code in modules that are never called)
 - rust-lang#92277 (rustc_metadata: Stop passing `CrateMetadataRef` by reference (step 1))
 - rust-lang#92334 (rustdoc: Preserve rendering of macro_rules matchers when possible)
 - rust-lang#92807 (Update cargo)
 - rust-lang#92832 (Update RELEASES for 1.58.)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit ac81a13 into rust-lang:master Jan 14, 2022
@rustbot rustbot added this to the 1.60.0 milestone Jan 14, 2022
@dtolnay dtolnay deleted the rustdocmatcher branch January 25, 2022 20:12
ehuss added a commit to ehuss/rust that referenced this pull request Jan 30, 2022
Render more readable macro matcher tokens in rustdoc

Follow-up to rust-lang#92334.

This PR lifts some of the token rendering logic from https://github.com/dtolnay/prettyplease into rustdoc so that even the matchers for which a source code snippet is not available (because they are macro-generated, or any other reason) follow some baseline good assumptions about where the tokens in the macro matcher are appropriate to space.

The below screenshots show an example of the difference using one of the gnarliest macros I could find. Some things to notice:

- In the **before**, notice how a couple places break in between `$(....)`↵`*`, which is just about the worst possible place that it could break.

- In the **before**, the lines that wrapped are weirdly indented by 1 space of indentation relative to column 0. In the **after**, we use the typical way of block indenting in Rust syntax which is put the open/close delimiters on their own line and indent their contents by 4 spaces relative to the previous line (so 8 spaces relative to column 0, because the matcher itself is indented by 4 relative to the `macro_rules` header).

- In the **after**, macro_rules metavariables like `$tokens:tt` are kept together, which is how just about everybody writing Rust today writes them.

## Before

![Screenshot from 2022-01-14 13-05-53](https://user-images.githubusercontent.com/1940490/149585105-1f182b78-751f-421f-a234-9dbc04fa3bbd.png)

## After

![Screenshot from 2022-01-14 13-06-04](https://user-images.githubusercontent.com/1940490/149585118-d4b52ea7-3e67-4b6e-a12b-31dfb8172f86.png)

r? `@camelid`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) 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.

rustdoc: Regression in whitespacing inside macro_rules matchers
8 participants