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

librustdoc: adopt let else in more places #94139

Merged
merged 1 commit into from
Mar 14, 2022

Conversation

est31
Copy link
Member

@est31 est31 commented Feb 18, 2022

Continuation of #89933, #91018, #91481, #93046, #93590, #94011.

I have extended my clippy lint to also recognize tuple passing and match statements. The diff caused by fixing it is way above 1 thousand lines. Thus, I split it up into multiple pull requests to make reviewing easier. This PR handles librustdoc.

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

Some changes occurred in clean/types.rs.

cc @camelid

@rust-highfive
Copy link
Collaborator

r? @CraftSpider

(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 Feb 18, 2022
@camelid
Copy link
Member

camelid commented Feb 19, 2022

I'm not really in favor of this change. It creates a lot of git history churn, and in most cases, it doesn't seem like an improvement. I think let_else is a great feature, but I don't think we should change all pre-existing code to use it. I really only think we should change existing code if it's highly-nested.

Copy link
Contributor

@bugadani bugadani left a comment

Choose a reason for hiding this comment

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

Looks like let_else shines in two places:

  • When the code is formatted so that let and else are both on the same column (like in unindent_comments.rs) This has a nice visual rythm to it.
  • Or, when the code is simple enough for the whole thing to fit in a single line.

Apart from these two cases, I'm having some difficulty with the "glanceability" of the statement, which I think might go away as I start reading and writing more code with let_else.

src/librustdoc/doctest.rs Outdated Show resolved Hide resolved
src/librustdoc/clean/mod.rs Outdated Show resolved Hide resolved
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 19, 2022
Adopt let else in more places

Continuation of rust-lang#89933, rust-lang#91018, rust-lang#91481, rust-lang#93046, rust-lang#93590, rust-lang#94011.

I have extended my clippy lint to also recognize tuple passing and match statements. The diff caused by fixing it is way above 1 thousand lines. Thus, I split it up into multiple pull requests to make reviewing easier. This is the biggest of these PRs and handles the changes outside of rustdoc, rustc_typeck, rustc_const_eval, rustc_trait_selection, which were handled in PRs rust-lang#94139, rust-lang#94142, rust-lang#94143, rust-lang#94144.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 19, 2022
Adopt let else in more places

Continuation of rust-lang#89933, rust-lang#91018, rust-lang#91481, rust-lang#93046, rust-lang#93590, rust-lang#94011.

I have extended my clippy lint to also recognize tuple passing and match statements. The diff caused by fixing it is way above 1 thousand lines. Thus, I split it up into multiple pull requests to make reviewing easier. This is the biggest of these PRs and handles the changes outside of rustdoc, rustc_typeck, rustc_const_eval, rustc_trait_selection, which were handled in PRs rust-lang#94139, rust-lang#94142, rust-lang#94143, rust-lang#94144.
@bors
Copy link
Contributor

bors commented Mar 2, 2022

☔ The latest upstream changes (presumably #93244) made this pull request unmergeable. Please resolve the merge conflicts.

@est31
Copy link
Member Author

est31 commented Mar 2, 2022

r? @notriddle

Copy link
Member

@camelid camelid left a comment

Choose a reason for hiding this comment

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

I still don't think this change is worth the churn, but if people prefer the new version, can you at least put the else on a separate line to improve visual clarity? The lack of braces around the let's value makes it hard to read the one-line version.

@notriddle
Copy link
Contributor

notriddle commented Mar 2, 2022

can you at least put the else on a separate line to improve visual clarity?

So, basically, this issue is blocked on rust-lang/rustfmt#4914 and rust-lang/style-team#165?

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Mar 3, 2022
Use ? operator in one instance instead of manual match

As suggested [here](rust-lang#94139 (comment)).

r? `@notriddle`
@est31
Copy link
Member Author

est31 commented Mar 3, 2022

I've put else onto a separate line. What do you think @camelid ?

As for blocking it on established formatting rules, you can absolutely do that, but I think one can just use whatever formatting one thinks is best and then have rustfmt reformat it once it has established a format.

@camelid
Copy link
Member

camelid commented Mar 3, 2022

Ok, now that more of the let-elses have line breaks, I feel better about this change. I do think the churn is not great, but I won't block this PR on that.

@bors
Copy link
Contributor

bors commented Mar 4, 2022

☔ The latest upstream changes (presumably #94009) made this pull request unmergeable. Please resolve the merge conflicts.

Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Mar 4, 2022
Use if let instead of manual match

Factored out of rust-lang#94139 . `if let` is better here than both `let ... else` and `let ... = match`.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Mar 4, 2022
Use if let instead of manual match

Factored out of rust-lang#94139 . `if let` is better here than both `let ... else` and `let ... = match`.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Mar 4, 2022
Use if let instead of manual match

Factored out of rust-lang#94139 . `if let` is better here than both `let ... else` and `let ... = match`.
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Mar 4, 2022
Use if let instead of manual match

Factored out of rust-lang#94139 . `if let` is better here than both `let ... else` and `let ... = match`.
@est31
Copy link
Member Author

est31 commented Mar 13, 2022

I've updated the PR. @notriddle is there anything left to do? As for the formatting, I can do it any way you want. Rustfmt won't change anything about it until it is established how to format it.

@notriddle
Copy link
Contributor

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Mar 13, 2022

📌 Commit 565f644 has been approved by notriddle

@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 Mar 13, 2022
@bors
Copy link
Contributor

bors commented Mar 14, 2022

⌛ Testing commit 565f644 with merge b751124...

@bors
Copy link
Contributor

bors commented Mar 14, 2022

☀️ Test successful - checks-actions
Approved by: notriddle
Pushing b751124 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Mar 14, 2022
@bors bors merged commit b751124 into rust-lang:master Mar 14, 2022
@rustbot rustbot added this to the 1.61.0 milestone Mar 14, 2022
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (b751124): comparison url.

Summary: This benchmark run did not return any relevant results. 16 results were found to be statistically significant but too small to be relevant.

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

@rustbot label: -perf-regression

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. 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.

9 participants