-
Notifications
You must be signed in to change notification settings - Fork 1.9k
overhaul int_plus_one
#16373
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
overhaul int_plus_one
#16373
Conversation
removes the need for a wildcard match
By building the whole suggestion in `emit_suggestion`, we avoid the need to thread `Applicability` through `check_binop` into `generate_suggestion`
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.
This is already quite good, I merely have a few nits.
clippy_lints/src/int_plus_one.rs
Outdated
| if Self::is_one(rhslhs) { | ||
| Some((lhs, rhsrhs)) | ||
| } else if Self::is_one(rhsrhs) { | ||
| Some((lhs, rhslhs)) | ||
| } else { | ||
| None | ||
| } |
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.
We could factor that out into a function we can call with lhs, rhslhs, rhsrhs and below with rhs, lhslhs, lhsrhs.
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 thought I could go one step further and create a function for x-1 as well -- do let me know if you think that overabstracts it
reduces duplication
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.
Thank you!
changelog: [
int_plus_one]: respect reduced applicabilitychangelog: [
int_plus_one]: fix FN with negative literals, e.g.-1 + x <= y