Skip to content

Commit c97b476

Browse files
excessive_precision: Fix false positive when exponent has leading zero (#14824)
Fixes #6341. changelog: [`excessive_precision`] no longer triggers on an exponent with leading zeros
2 parents dcd8bb6 + e666b83 commit c97b476

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

clippy_lints/src/float_literal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl<'tcx> LateLintPass<'tcx> for FloatLiteral {
126126
},
127127
);
128128
}
129-
} else if digits > max as usize && float_str.len() < sym_str.len() {
129+
} else if digits > max as usize && count_digits(&float_str) < count_digits(sym_str) {
130130
span_lint_and_then(
131131
cx,
132132
EXCESSIVE_PRECISION,

tests/ui/excessive_precision.fixed

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ fn main() {
7979
// issue #2840
8080
let num = 0.000_000_000_01e-10f64;
8181

82+
// issue #6341
83+
let exponential: f64 = 4.886506780521244E-03;
84+
8285
// issue #7744
8386
let _ = 2.225_073_858_507_201e-308_f64;
8487
//~^ excessive_precision

tests/ui/excessive_precision.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ fn main() {
7979
// issue #2840
8080
let num = 0.000_000_000_01e-10f64;
8181

82+
// issue #6341
83+
let exponential: f64 = 4.886506780521244E-03;
84+
8285
// issue #7744
8386
let _ = 2.225_073_858_507_201_1e-308_f64;
8487
//~^ excessive_precision

tests/ui/excessive_precision.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ LL + let bad_bige32: f32 = 1.123_456_8E-10;
157157
|
158158

159159
error: float has excessive precision
160-
--> tests/ui/excessive_precision.rs:83:13
160+
--> tests/ui/excessive_precision.rs:86:13
161161
|
162162
LL | let _ = 2.225_073_858_507_201_1e-308_f64;
163163
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -169,7 +169,7 @@ LL + let _ = 2.225_073_858_507_201e-308_f64;
169169
|
170170

171171
error: float has excessive precision
172-
--> tests/ui/excessive_precision.rs:87:13
172+
--> tests/ui/excessive_precision.rs:90:13
173173
|
174174
LL | let _ = 1.000_000_000_000_001e-324_f64;
175175
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -181,7 +181,7 @@ LL + let _ = 0_f64;
181181
|
182182

183183
error: float has excessive precision
184-
--> tests/ui/excessive_precision.rs:98:20
184+
--> tests/ui/excessive_precision.rs:101:20
185185
|
186186
LL | const _: f64 = 3.0000000000000000e+00;
187187
| ^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)