-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fix integer_division false negative for NonZero denominators #14664
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 integer_division false negative for NonZero denominators #14664
Conversation
Failed to set assignee to
|
r? clippy |
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.
Great bugfix, althought I have some light comments =^w^= 🐱
@@ -12,4 +16,8 @@ fn main() { | |||
//~^ integer_division | |||
|
|||
let x = 1. / 2.0; | |||
|
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 for future resilience, could you also add a test for NonZero / <integer>
and NonZero / NonZero
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.
Testing I see the following
error[E0369]: cannot divide std::num::NonZero<u32> by std::num::NonZero<u32>
the foreign item type std::num::NonZero<u32> doesn't implement std::ops::Div
and
error[E0369]: cannot divide std::num::NonZero<u32> by u32
the foreign item type std::num::NonZero<u32> doesn't implement std::ops::Div<u32>
so I adjusted condition as well
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.
Interesting, although I guess that makes sense because the only scenario where absolutely making sure that an integer is non-zero would be in the denominator.
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.
It would also be unintuitive (and non-composable), because NonZero(1) / NonZero(2)
is zero, so the returned type would always have to be the underlying integer.
74a1494
to
b940e64
Compare
b940e64
to
1fbfbb5
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.
LGTM, thanks ❤️
Close #14652
changelog: [
integer_division
]: fix false negative for NonZero denominators