-
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
Adds lint for integer division #4195
Adds lint for integer division #4195
Conversation
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.
Thanks for the contribution! Just a NIT and this can get merged.
clippy_lints/src/integer_division.rs
Outdated
then { | ||
let (left_ty, right_ty) = (cx.tables.expr_ty(left), cx.tables.expr_ty(right)); | ||
if left_ty.is_integral() && right_ty.is_integral() { | ||
return true; |
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.
You can return this directly:
return true; | |
return left_ty.is_integral() && right_ty.is_integral(); |
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.
Done at b364eb7.
By the way, can we add a lint rule for that? Is this lintable?
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.
When I saw this, I also instantly that this could be linted. But this is pretty hard to lint and even harder / impossible inside a macro. This is only possible iff
if some_bool_expr {
return true;
}
is the second to last expression and in every other case we return false. The needless_bool
lint already lints the easy if _ { true } else { false }
case. Maybe this could be extended. But this would have many edge cases.
87ff215
to
b364eb7
Compare
Thanks! @bors r+ |
📌 Commit b364eb7 has been approved by |
☀️ Test successful - checks-travis, status-appveyor |
Hi, folks! This is my first contribution to clippy and my first real piece of Rust code.
This is supposed to add a lint that warns for division of integers (#109). Please let me know if you need any changes.
Fixes #109
changelog: Add lint for integer division