Skip to content

fix [excessive_precision] suggestions on floats written in scientific notation #13096

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

Merged
merged 1 commit into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clippy_utils/src/numeric_literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ impl<'a> NumericLiteral<'a> {
if !exponent.is_empty() && exponent != "0" {
output.push_str(separator);
Self::group_digits(&mut output, exponent, group_size, true, false);
} else if exponent == "0" && self.fraction.is_none() && self.suffix.is_none() {
output.push_str(".0");
}
}

Expand Down
4 changes: 4 additions & 0 deletions tests/ui/excessive_precision.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,8 @@ fn main() {
const NEG_INF1: f32 = -1.0e+33f32;
const NEG_INF2: f64 = -1.0e+3300f64;
const NEG_INF3: f32 = -3.40282357e+38_f32;

// issue #12954
const _: f64 = 3.0;
const _: f64 = 3.0000000000000000;
}
4 changes: 4 additions & 0 deletions tests/ui/excessive_precision.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,8 @@ fn main() {
const NEG_INF1: f32 = -1.0e+33f32;
const NEG_INF2: f64 = -1.0e+3300f64;
const NEG_INF3: f32 = -3.40282357e+38_f32;

// issue #12954
const _: f64 = 3.0000000000000000e+00;
const _: f64 = 3.0000000000000000;
}
8 changes: 7 additions & 1 deletion tests/ui/excessive_precision.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,11 @@ error: float has excessive precision
LL | let _ = 1.000_000_000_000_001e-324_f64;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0_f64`

error: aborting due to 15 previous errors
error: float has excessive precision
--> tests/ui/excessive_precision.rs:83:20
|
LL | const _: f64 = 3.0000000000000000e+00;
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `3.0`

error: aborting due to 16 previous errors