-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have
Description
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
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have