-
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
assert_eq! with a literal float should probably fire float_cmp_const not float_cmp #6817
Comments
@rustbot claim |
Hi, I need some help with this, I see that the is_named_constant() in clippy_lints/src/misc.rs returns false, I see there is a difference in expression objects between the left and right expressions in a regular equality check and an assert_eq macro, could someone point me in the right direction to tackle this, CC @flip1995 |
Hmm. I would start to add The |
This is how the debug expressions look like
|
Ah this makes sense. Looking at the macro expansion: match (&RADIANS_PER_FURMAN, &0.000_095_873_799_242_852_57) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val,
::core::option::Option::None);
}
}
} Kind of weird, that rustc can't figure out that rust-clippy/clippy_utils/src/consts.rs Lines 327 to 328 in 63aca96
Can you verify that this function gets called, while evaluating the constants? And possibly what the result of this is: rust-clippy/clippy_utils/src/consts.rs Lines 339 to 350 in 63aca96
|
This function indeed gets called, result of left and right expressions
|
So the rust-clippy/clippy_utils/src/consts.rs Lines 359 to 360 in 63aca96
|
Thanks, I'll look into that |
I'll not be able to look at this for the next 15 days, unassigning if anyone wants to take it up in the mean time, I was last working on lowering the expression to extract the type |
As far as I can see, |
Yeah, that's changed since I originally filed the issue. I updated the OP to not be incorrect. Adjusting which lint gets emitted would still be more correct, but yes, it's significantly less impactful of a change with both lints being allow by default now. But it does still matter for when one but not the other is enabled. |
Example:
Here
float_cmp
fires. Given that this is comparing aconst
to a literal float, however, this should almost certainly befloat_cmp_const
instead (which is in the restriction group, as opposed tofloat_cmp
in pedantic). (float_cmp
used to be more aggressively linted, but both lints are allow by default nowadays.)This seems like a reasonable usage of exact floating point equality: defining
const
s with the intuitive definition and asserting that the produced value is precise within ±½ ULP, by checking against an alternatively produced value.(Yes, furmans are a real unit, even if unusual/whimsical. Furman is the name for 1/65536th of a revolution, such that one revolution divides evenly into
u16
.)The text was updated successfully, but these errors were encountered: