-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Use let else #8358
Use let else #8358
Conversation
There's already a PR #7104 but it's currently blocked on |
I probably should have checked for that before working on this. |
With that said, your PR is much more recent, so if it gets support soon at least your PR is more up to date and therefore more likely to get merged |
For the tracking issue in the rustfmt side rust-lang/rustfmt#4914 |
It looks like rustfmt's implementation work is more-or-less there also. Apparently held up by 'release/communication work'. |
|
You can do that in GitHub UI for reviews:
I don't think |
This is no longer blocked, but it's going to be easier to just remake this than to fix the merge conflicts :) Please feel free to do so: this is generally a really nice change to make! |
Objective
Now that
let...else
is stable, we can improve legibility and reduce indentation in code that currently usesif let
, followed by large blocks of code.Solution
Replace instances of
if let
ormatch...return
to uselet...else
.The first commit in this PR fixes instances of
clippy::manual_let_else
, which detects basic instances ofmatch
that we can replace easily. The second commit in this PR additionally changes large function and loop blocks to return or continue early when a value is not matched. This unfortunately causes a lot of changed lines in the PR.We can just cherry pick the first commit if we don't want to change beyond the pedantic clippy lint, or break these changes up into multiple PRs.
EDIT: For any potential reviewers, you might consider viewing the changes in your local editor or somewhere else that ignores indentation changes when highlighting lines.