about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Hackner <mhackner@gmail.com>2025-05-16 21:35:09 -0700
committerMichael Hackner <mhackner@gmail.com>2025-05-16 21:35:09 -0700
commite666b83b11689a17571305592f4b67dce6bc1d4a (patch)
treea93bd863cda6549dfbcc9957d41810a583feaaa5
parentdcd8bb6d7e5d7eab9d815150a1cc09c24928a672 (diff)
downloadrust-e666b83b11689a17571305592f4b67dce6bc1d4a.tar.gz
rust-e666b83b11689a17571305592f4b67dce6bc1d4a.zip
excessive_precision: Fix false positive when exponent has leading zero
-rw-r--r--clippy_lints/src/float_literal.rs2
-rw-r--r--tests/ui/excessive_precision.fixed3
-rw-r--r--tests/ui/excessive_precision.rs3
-rw-r--r--tests/ui/excessive_precision.stderr6
4 files changed, 10 insertions, 4 deletions
diff --git a/clippy_lints/src/float_literal.rs b/clippy_lints/src/float_literal.rs
index 012ad8e1a22..c51267567d0 100644
--- a/clippy_lints/src/float_literal.rs
+++ b/clippy_lints/src/float_literal.rs
@@ -126,7 +126,7 @@ impl<'tcx> LateLintPass<'tcx> for FloatLiteral {
                         },
                     );
                 }
-            } else if digits > max as usize && float_str.len() < sym_str.len() {
+            } else if digits > max as usize && count_digits(&float_str) < count_digits(sym_str) {
                 span_lint_and_then(
                     cx,
                     EXCESSIVE_PRECISION,
diff --git a/tests/ui/excessive_precision.fixed b/tests/ui/excessive_precision.fixed
index 99d09774d16..8a8c2e1939c 100644
--- a/tests/ui/excessive_precision.fixed
+++ b/tests/ui/excessive_precision.fixed
@@ -79,6 +79,9 @@ fn main() {
     // issue #2840
     let num = 0.000_000_000_01e-10f64;
 
+    // issue #6341
+    let exponential: f64 = 4.886506780521244E-03;
+
     // issue #7744
     let _ = 2.225_073_858_507_201e-308_f64;
     //~^ excessive_precision
diff --git a/tests/ui/excessive_precision.rs b/tests/ui/excessive_precision.rs
index a542fb2e7e3..5dcf55cb927 100644
--- a/tests/ui/excessive_precision.rs
+++ b/tests/ui/excessive_precision.rs
@@ -79,6 +79,9 @@ fn main() {
     // issue #2840
     let num = 0.000_000_000_01e-10f64;
 
+    // issue #6341
+    let exponential: f64 = 4.886506780521244E-03;
+
     // issue #7744
     let _ = 2.225_073_858_507_201_1e-308_f64;
     //~^ excessive_precision
diff --git a/tests/ui/excessive_precision.stderr b/tests/ui/excessive_precision.stderr
index 934a367e106..f5eeadf0c8c 100644
--- a/tests/ui/excessive_precision.stderr
+++ b/tests/ui/excessive_precision.stderr
@@ -157,7 +157,7 @@ LL +     let bad_bige32: f32 = 1.123_456_8E-10;
    |
 
 error: float has excessive precision
-  --> tests/ui/excessive_precision.rs:83:13
+  --> tests/ui/excessive_precision.rs:86:13
    |
 LL |     let _ = 2.225_073_858_507_201_1e-308_f64;
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -169,7 +169,7 @@ LL +     let _ = 2.225_073_858_507_201e-308_f64;
    |
 
 error: float has excessive precision
-  --> tests/ui/excessive_precision.rs:87:13
+  --> tests/ui/excessive_precision.rs:90:13
    |
 LL |     let _ = 1.000_000_000_000_001e-324_f64;
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -181,7 +181,7 @@ LL +     let _ = 0_f64;
    |
 
 error: float has excessive precision
-  --> tests/ui/excessive_precision.rs:98:20
+  --> tests/ui/excessive_precision.rs:101:20
    |
 LL |     const _: f64 = 3.0000000000000000e+00;
    |                    ^^^^^^^^^^^^^^^^^^^^^^