-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add new lint [unused_rounding]
#8866
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
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @llogiq (or someone else) soon. Please see the contribution instructions for more information. |
clippy_lints/src/unused_rounding.rs
Outdated
} else { | ||
"" | ||
}; | ||
if f.fract() < f64::EPSILON { |
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.
Is the test that f
is a whole number? f64::EPSILON
is 2-53 but it's possible for a positive float to be smaller than that. Try let _ = 2E-54f64.floor();
in your tests.
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're right. Thanks! This should be fixed now
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.
Good job! 👍
I'd also like to see the test @mikerite proposed. And I wonder if the lint should be omitted in test code (we have an in_test
function in clippy_utils
, but it requires a LateContext
).
clippy_lints/src/unused_rounding.rs
Outdated
#[clippy::version = "1.62.0"] | ||
pub UNUSED_ROUNDING, | ||
nursery, | ||
"Rounding a whole number literal, which is useless" |
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.
"Rounding a whole number literal, which is useless" | |
"Uselessly rounding a whole number floating-point literal" |
@llogiq I made both changes. I'm not sure about omitting it in tests, so I left that the same for now. What would be the reason for doing that? |
☔ The latest upstream changes (presumably #8882) made this pull request unmergeable. Please resolve the merge conflicts. |
Ah shoot, I messed up with the rebase, didn't I? |
ed20458
to
ec3fdd6
Compare
ec3fdd6
to
f489954
Compare
Thank you! @bors r+ |
📌 Commit f489954 has been approved by |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
fixes #39
changelog: added a
[`unused_rounding`]
lint to check for the rounding of whole-number literals