Skip to content

Commit 0ee9f44

Browse files
committed
Auto merge of #13096 - apoisternex:issue12954, r=y21
fix [`excessive_precision`] suggestions on floats written in scientific notation fixes #12954 changelog: fix [`excessive_precision`] suggestions on float literal written in scientific notation
2 parents eb4d88e + 489a778 commit 0ee9f44

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

clippy_utils/src/numeric_literal.rs

+2
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ impl<'a> NumericLiteral<'a> {
164164
if !exponent.is_empty() && exponent != "0" {
165165
output.push_str(separator);
166166
Self::group_digits(&mut output, exponent, group_size, true, false);
167+
} else if exponent == "0" && self.fraction.is_none() && self.suffix.is_none() {
168+
output.push_str(".0");
167169
}
168170
}
169171

tests/ui/excessive_precision.fixed

+4
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,8 @@ fn main() {
7878
const NEG_INF1: f32 = -1.0e+33f32;
7979
const NEG_INF2: f64 = -1.0e+3300f64;
8080
const NEG_INF3: f32 = -3.40282357e+38_f32;
81+
82+
// issue #12954
83+
const _: f64 = 3.0;
84+
const _: f64 = 3.0000000000000000;
8185
}

tests/ui/excessive_precision.rs

+4
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,8 @@ fn main() {
7878
const NEG_INF1: f32 = -1.0e+33f32;
7979
const NEG_INF2: f64 = -1.0e+3300f64;
8080
const NEG_INF3: f32 = -3.40282357e+38_f32;
81+
82+
// issue #12954
83+
const _: f64 = 3.0000000000000000e+00;
84+
const _: f64 = 3.0000000000000000;
8185
}

tests/ui/excessive_precision.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -91,5 +91,11 @@ error: float has excessive precision
9191
LL | let _ = 1.000_000_000_000_001e-324_f64;
9292
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0_f64`
9393

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

0 commit comments

Comments
 (0)