Skip to content

False positive in excessive_precision for floats that are already in shortest form #7721

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

Closed
dtolnay opened this issue Sep 26, 2021 · 0 comments · Fixed by #7722
Closed

False positive in excessive_precision for floats that are already in shortest form #7721

dtolnay opened this issue Sep 26, 2021 · 0 comments · Fixed by #7722
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

Comments

@dtolnay
Copy link
Member

dtolnay commented Sep 26, 2021

fn main() {
    let _ = 0.123_456_789_012_345_67;
}
warning: float has excessive precision
 --> src/main.rs:2:13
  |
2 |     let _ = 0.123_456_789_012_345_67;
  |             ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.123_456_789_012_345_66`
  |
  = note: `#[warn(clippy::excessive_precision)]` on by default
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#excessive_precision

Clippy's suggestion is the following diff:

-     let _ = 0.123_456_789_012_345_67;
+     let _ = 0.123_456_789_012_345_66;

It seems wrong to call this excessive precision when both representations have identical precision. Probably there is a reason that the one the human wrote is more meaningful in context and should be left as is.


Meta

Rust version (rustc -Vv):

rustc 1.57.0-nightly (addb4da68 2021-09-25)
binary: rustc
commit-hash: addb4da686a97da46159f0123cb6cdc2ce3d7fdb
commit-date: 2021-09-25
host: x86_64-unknown-linux-gnu
release: 1.57.0-nightly
LLVM version: 13.0.0
@dtolnay dtolnay added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Sep 26, 2021
@bors bors closed this as completed in 30fe4ba Sep 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant