about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-10-02 16:12:30 +0000
committerbors <bors@rust-lang.org>2021-10-02 16:12:30 +0000
commitda3b4b45948d8859fb9b19ae84f4ddb6bd497895 (patch)
tree15a95932a4521cb4d4f2b76ad5cbc3e6331392e5
parentfe999e88edd2254124be6419607bd29156841f59 (diff)
parent6bf5c0b185e37f64661e16938e18d68abd2accc4 (diff)
downloadrust-da3b4b45948d8859fb9b19ae84f4ddb6bd497895.tar.gz
rust-da3b4b45948d8859fb9b19ae84f4ddb6bd497895.zip
Auto merge of #7747 - Manishearth:excessive-precision, r=xFrednet
Correctly handle signs in exponents in numeric_literal::format()

Fixes #7744

changelog: Correctly handle signs in exponents in `numeric_literal::format()`
-rw-r--r--clippy_utils/src/numeric_literal.rs7
-rw-r--r--tests/ui/excessive_precision.fixed3
-rw-r--r--tests/ui/excessive_precision.rs3
-rw-r--r--tests/ui/excessive_precision.stderr8
4 files changed, 20 insertions, 1 deletions
diff --git a/clippy_utils/src/numeric_literal.rs b/clippy_utils/src/numeric_literal.rs
index 4a28c7dd9a0..98f65039b7d 100644
--- a/clippy_utils/src/numeric_literal.rs
+++ b/clippy_utils/src/numeric_literal.rs
@@ -177,6 +177,13 @@ impl<'a> NumericLiteral<'a> {
 
         let mut digits = input.chars().filter(|&c| c != '_');
 
+        // The exponent may have a sign, output it early, otherwise it will be
+        // treated as a digit
+        if let Some('-') = digits.clone().next() {
+            let _ = digits.next();
+            output.push('-');
+        }
+
         let first_group_size;
 
         if partial_group_first {
diff --git a/tests/ui/excessive_precision.fixed b/tests/ui/excessive_precision.fixed
index 90376620a9f..65096d6b219 100644
--- a/tests/ui/excessive_precision.fixed
+++ b/tests/ui/excessive_precision.fixed
@@ -60,4 +60,7 @@ fn main() {
 
     // issue #2840
     let num = 0.000_000_000_01e-10f64;
+
+    // issue #7744
+    let _ = 2.225_073_858_507_201e-308_f64;
 }
diff --git a/tests/ui/excessive_precision.rs b/tests/ui/excessive_precision.rs
index ce4722a90f9..4db6e4d4831 100644
--- a/tests/ui/excessive_precision.rs
+++ b/tests/ui/excessive_precision.rs
@@ -60,4 +60,7 @@ fn main() {
 
     // issue #2840
     let num = 0.000_000_000_01e-10f64;
+
+    // issue #7744
+    let _ = 2.225_073_858_507_201_1e-308_f64;
 }
diff --git a/tests/ui/excessive_precision.stderr b/tests/ui/excessive_precision.stderr
index e59c20c30b4..c9418f73d98 100644
--- a/tests/ui/excessive_precision.stderr
+++ b/tests/ui/excessive_precision.stderr
@@ -78,5 +78,11 @@ error: float has excessive precision
 LL |     let bad_bige32: f32 = 1.123_456_788_888E-10;
    |                           ^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `1.123_456_8E-10`
 
-error: aborting due to 13 previous errors
+error: float has excessive precision
+  --> $DIR/excessive_precision.rs:65:13
+   |
+LL |     let _ = 2.225_073_858_507_201_1e-308_f64;
+   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `2.225_073_858_507_201e-308_f64`
+
+error: aborting due to 14 previous errors