-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Fix some suggestions for redundant_pattern_matching #4352
Fix some suggestions for redundant_pattern_matching #4352
Conversation
I have 2 concerns here:
While this expression:
returns a
returns the unit type * Since stray ** That would be a rust-clippy/clippy_lints/src/utils/mod.rs Lines 534 to 536 in 7bd7d40
to create the new block |
Oh you already mentioned my first point. Without fixing this, we should just turn the suggestion into |
Yeah, that was also brought up as a problem in #4344 and this PR doesn't address that.
It seems like there are a lot of test cases missing. Maybe these suggestions should be marked as |
Just edited my first comment 😉 |
85a736c
to
400015f
Compare
@flip1995 Was this what you had in mind? I opted to stop suggesting the |
f1d32e8
to
d41a5d6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that was somehow what I had in mind, but there are different cases, that we need to take into account before we can turn this suggestion to MachineApplicable
.
New test cases look good now. One test case should be added for the auto applicability:
let x = if let Some(_) = opt { true } else { false };
takes_bool(x);
let y = if let Some(_) = opt {};
takes_unit(y);
to make sure we pass the type checker with the suggestions. I would just add them now, so we don't forget about them once someone makes these suggestions auto applicable.
Fixes the problem displayed in rust-lang#4344 (comment). We now append `{}` to the suggestion so that the conditional has the correct syntax again. (If we were to _remove_ the `if` instead, it would trigger the `unused_must_use` warning for `#[must_use]` types.
These should make sure that, when the suggestions are fixed, they are fixed for all these cases.
d41a5d6
to
436d429
Compare
@bors r+ |
📌 Commit 436d429 has been approved by |
Fix some suggestions for redundant_pattern_matching .. and change the Applicability to `MaybeIncorrect`. Fixes the problem displayed in #4344 (comment). We now append `{}` to the suggestion so that the conditional has the correct syntax again. (If we were to _remove_ the `if` instead, it would trigger the `unused_must_use` warning for `#[must_use]` types.) changelog: Fix some suggestions for `redundant_pattern_matching`
☀️ Test successful - checks-travis, status-appveyor |
.. and change the Applicability to
MaybeIncorrect
.Fixes the problem displayed in #4344 (comment).
We now append
{}
to the suggestion so that the conditional has thecorrect syntax again.
(If we were to remove the
if
instead, it would trigger theunused_must_use
warning for#[must_use]
types.)changelog: Fix some suggestions for
redundant_pattern_matching