-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
New lint: unnecessary_map_or
#11796
New lint: unnecessary_map_or
#11796
Conversation
r? @Centri3 (rustbot has picked a reviewer for you, use r? to override) |
Hi, apologies for the lack of movement on this. I’ll make changes based on the review now, and once everything is up to standard I’ll go through the conflicts. |
ad74a63
to
abd23dc
Compare
@rustbot ready |
☔ The latest upstream changes (presumably #12310) made this pull request unmergeable. Please resolve the merge conflicts. |
2acf442
to
857081a
Compare
☔ The latest upstream changes (presumably #12507) made this pull request unmergeable. Please resolve the merge conflicts. |
This comment was marked as resolved.
This comment was marked as resolved.
2f923e6
to
c8341ac
Compare
☔ The latest upstream changes (presumably #12999) made this pull request unmergeable. Please resolve the merge conflicts. |
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.
Just a couple more changes then this is good <3
686975d
to
d305884
Compare
Never mind: My GH view was outdated |
☔ The latest upstream changes (presumably #13168) made this pull request unmergeable. Please resolve the merge conflicts. |
c558bf5
to
a25b386
Compare
☔ The latest upstream changes (presumably #13496) made this pull request unmergeable. Please resolve the merge conflicts. |
35ad982
to
c150da9
Compare
Apologies for the slow turnover again. I hope this is the last of the issues now and this can finally be merged 😅 |
It looks like you marked the comment in #11796 (comment) as resolved but it is not. The example: fn main() {
struct S;
let r: Result<i32, S> = Ok(3);
let _ = r.map_or(false, |x| x == 7);
} will incorrectly suggest using Could you also add this as a testcase? As well as one where |
let _ = Some(5) == Some(5); | ||
let _ = Some(5) != Some(5); | ||
let _ = Some(5) == Some(5); | ||
let _ = (Some(5) == Some(5)); |
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.
These (
should be removed, shouldn't they?
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.
I think this is just an effect of maybe_par
deciding they should be present. While I'd usually agree, I'm not sure there is a better way to tackle that?
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.
maybe_par
is rather overeager, but unused_parens
will usually catch them anyway (outside of arithmetic, for readability). New lints triggering on fixed code in a cascade is fine
Is it time to open a FCP for this lint? I keep seeing |
☔ The latest upstream changes (presumably #13437) made this pull request unmergeable. Please resolve the merge conflicts. |
Opened the FCP. Can you squash? |
5e9ca40
to
fc78116
Compare
Squash done, ready for final comments/changes then hopefully can finally get this merged. Apologies again for how long this took. |
@Jacherr It looks like Note that tests that don't involve |
I am happy with merging this as-is if no concerns come up, and having that done later. |
This seems reasonable indeed. |
☔ The latest upstream changes (presumably #13639) made this pull request unmergeable. Please resolve the merge conflicts. |
(an alternative is to merge #13653 which contains this PR, updated, and the |
fc78116
to
ca5b59a
Compare
Hopefully, everything is in order for merge now. Ideally, as mentioned in the FCP, this can be merged and the additional |
0e440e1
to
89210d7
Compare
Thanks for your work on this :) I doubt anybody will object the lint being added so let's put it to rest ❤️ |
Closes #10118
This lint checks
map_or
method calls to check if they can be consolidated down to something simpler and/or more readable.For example, the code
can be rewritten as
In addition, when the closure is more complex, the code can be altered from, say,
into
This lint also considers cases where the
map_or
can be chained with other method calls, and accommodates accordingly by adding extra parentheses as needed to the suggestion.changelog: add new lint
unnecessary_map_or