Skip to content
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

The excessive_precision linter suggestion causes a compilation error #12954

Closed
tencek opened this issue Jun 18, 2024 · 0 comments · Fixed by #13096
Closed

The excessive_precision linter suggestion causes a compilation error #12954

tencek opened this issue Jun 18, 2024 · 0 comments · Fixed by #13096
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

@tencek
Copy link

tencek commented Jun 18, 2024

Summary

The lint suggests truncating 3.0000000000000000e+00 to 3 which causes a "mismatched types" compilation error.

Lint Name

clippy::excessive_precision

Reproducer

I tried this code:

pub const DATA: f64 = 3.0000000000000000e+00;

I saw this happen:

cargo clippy --fix --allow-staged
    Checking clippy_test v0.1.0 (C:\dev\tencek\sandbox\rust\clippy_test)
warning: failed to automatically apply fixes suggested by rustc to crate `clippy_test`

after fixes were automatically applied the compiler reported errors within these files:

  * src\data.rs

This likely indicates a bug in either rustc or cargo itself,
and we would appreciate a bug report! You're likely to see
a number of compiler warnings after this message which cargo
attempted to fix but failed. If you could open an issue at
https://github.com/rust-lang/rust-clippy/issues
quoting the full output of this command we'd be very appreciative!
Note that you may be able to make some more progress in the near-term
fixing code with the `--broken-code` flag

The following errors were reported:
error[E0308]: mismatched types
 --> src\data.rs:1:23
  |
1 | pub const DATA: f64 = 3;
  |                       ^
  |                       |
  |                       expected `f64`, found integer
  |                       help: use a float literal: `3.0`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0308`.
Original diagnostics will follow.

warning: float has excessive precision
 --> src\data.rs:1:23
  |
1 | pub const DATA: f64 = 3.0000000000000000e+00;
  |                       ^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `3`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#excessive_precision
  = note: `#[warn(clippy::excessive_precision)]` on by default

warning: `clippy_test` (bin "clippy_test") generated 1 warning (run `cargo clippy --fix --bin "clippy_test"` to apply 1 suggestion)
warning: failed to automatically apply fixes suggested by rustc to crate `clippy_test`

after fixes were automatically applied the compiler reported errors within these files:

  * src\data.rs

This likely indicates a bug in either rustc or cargo itself,
and we would appreciate a bug report! You're likely to see
a number of compiler warnings after this message which cargo
attempted to fix but failed. If you could open an issue at
https://github.com/rust-lang/rust-clippy/issues
quoting the full output of this command we'd be very appreciative!
Note that you may be able to make some more progress in the near-term
fixing code with the `--broken-code` flag

The following errors were reported:
error[E0308]: mismatched types
 --> src\data.rs:1:23
  |
1 | pub const DATA: f64 = 3;
  |                       ^
  |                       |
  |                       expected `f64`, found integer
  |                       help: use a float literal: `3.0`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0308`.
Original diagnostics will follow.

I expected to see this happen:
Probably this:

pub const DATA: f64 = 3.0;

Version

rustc 1.79.0 (129f3b996 2024-06-10)
binary: rustc
commit-hash: 129f3b9964af4d4a709d1383930ade12dfe7c081
commit-date: 2024-06-10
host: x86_64-pc-windows-msvc
release: 1.79.0
LLVM version: 18.1.7

Additional Labels

I-suggestion-causing-error

@tencek tencek 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 Jun 18, 2024
bors added a commit that referenced this issue Jul 16, 2024
fix [`excessive_precision`] suggestions on floats written in scientific notation

fixes #12954

changelog: fix [`excessive_precision`] suggestions on float literal written in scientific notation
@bors bors closed this as completed in 489a778 Jul 16, 2024
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
1 participant