]> git.lizzy.rs Git - rust.git/commitdiff
Correctly handle signs in exponents in numeric_literal::format()
authorManish Goregaokar <manishsmail@gmail.com>
Sat, 2 Oct 2021 00:27:47 +0000 (17:27 -0700)
committerManish Goregaokar <manishsmail@gmail.com>
Sat, 2 Oct 2021 00:27:47 +0000 (17:27 -0700)
clippy_utils/src/numeric_literal.rs
tests/ui/excessive_precision.fixed
tests/ui/excessive_precision.stderr

index 4a28c7dd9a04a3885251ef7ab44e7d5ea65aa7fe..98f65039b7da9fb2765e72d7a6f6e44bd8ab077f 100644 (file)
@@ -177,6 +177,13 @@ pub fn group_digits(output: &mut String, input: &str, group_size: usize, partial
 
         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 {
index f57191d2ae5e0265aa2857ed23aee789cfc3f7ae..65096d6b219e3996719f2ae690fc9d9f704a3bde 100644 (file)
@@ -62,5 +62,5 @@ fn main() {
     let num = 0.000_000_000_01e-10f64;
 
     // issue #7744
-    let _ = 2.225_073_858_507_201e-_308_f64;
+    let _ = 2.225_073_858_507_201e-308_f64;
 }
index 4c8194b1d862b23406b0b162e1d33d71d967d1b9..c9418f73d9874b3ee81e722d280b36b67b5d46e8 100644 (file)
@@ -82,7 +82,7 @@ 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`
+   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `2.225_073_858_507_201e-308_f64`
 
 error: aborting due to 14 previous errors