excessive_precision should not lint when it's so excessive as to be clearly intentional #13855
Labels
C-bug
Category: Clippy is not doing the correct thing
I-false-positive
Issue: The lint was triggered on code it shouldn't have
Summary
Like how rust defines constants with clearly more precision than needed,
https://github.com/rust-lang/rust/blob/5dfe648b45659db8dd0a673a806bba3df84aa3af/library/core/src/num/f32.rs#L348-L358
For mathematical constants (that aren't already in
fNN::consts
) it's nice to just paste in the full value with way more precision that you could ever need, likeThat's 40 decimal sigfigs, aka about 132 binary sigfigs, which is well more than is needed for any built-in float type (even
f128
is only ≈33 decimal sigfigs).And changing that to
as clippy suggests obfuscates more than it helps, plus it makes it harder if you change from
f32
tof64
in the future.For constants that have just slightly too much precision, especially things that look like integers, this lint makes sense.
But when the coder is clearly not thinking that it'll be exactly representable -- I'll toss that 40 sigfig threshold as a first stab at how clippy could know that -- then telling them that there's excess precision is not valuable, and clippy should let it go.
(Other things you could consider here are things like suppressing it for
const
s defined with a type and a particularly-precise literal, or something.)Lint Name
excessive_precision
Reproducer
No response
Version
Additional Labels
No response
The text was updated successfully, but these errors were encountered: