about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-10-06 07:54:27 +0000
committerbors <bors@rust-lang.org>2021-10-06 07:54:27 +0000
commitc6b915825f279bd3f1bea4dbbbd2829a57308280 (patch)
tree48e0c2ba3a07fce18f50df9bd40cda24247f4d9e
parent871b8b5d4c980462ad4b665ee17157de0fab9da2 (diff)
parente476d05c8ff8fa149b31a9a02d6fa5503ccdd1af (diff)
downloadrust-c6b915825f279bd3f1bea4dbbbd2829a57308280.tar.gz
rust-c6b915825f279bd3f1bea4dbbbd2829a57308280.zip
Auto merge of #7774 - dswij:useless-exponent, r=llogiq
Useless exponent

Closes #7745

I'm open to some thoughts on dropping the exponents on suggestions when it's zero. I personally don't see any problem on this.

changelog: [`useless_exponent`] suggestion drops exponent when exponent value is zero
-rw-r--r--clippy_utils/src/numeric_literal.rs6
-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, 17 insertions, 3 deletions
diff --git a/clippy_utils/src/numeric_literal.rs b/clippy_utils/src/numeric_literal.rs
index 7ad21044d7d..68dd1b29845 100644
--- a/clippy_utils/src/numeric_literal.rs
+++ b/clippy_utils/src/numeric_literal.rs
@@ -157,8 +157,10 @@ impl<'a> NumericLiteral<'a> {
         }
 
         if let Some((separator, exponent)) = self.exponent {
-            output.push_str(separator);
-            Self::group_digits(&mut output, exponent, group_size, true, false);
+            if exponent != "0" {
+                output.push_str(separator);
+                Self::group_digits(&mut output, exponent, group_size, true, false);
+            }
         }
 
         if let Some(suffix) = self.suffix {
diff --git a/tests/ui/excessive_precision.fixed b/tests/ui/excessive_precision.fixed
index 65096d6b219..b74bda182be 100644
--- a/tests/ui/excessive_precision.fixed
+++ b/tests/ui/excessive_precision.fixed
@@ -63,4 +63,7 @@ fn main() {
 
     // issue #7744
     let _ = 2.225_073_858_507_201e-308_f64;
+
+    // issue #7745
+    let _ = 0_f64;
 }
diff --git a/tests/ui/excessive_precision.rs b/tests/ui/excessive_precision.rs
index 4db6e4d4831..6e84a71f24c 100644
--- a/tests/ui/excessive_precision.rs
+++ b/tests/ui/excessive_precision.rs
@@ -63,4 +63,7 @@ fn main() {
 
     // issue #7744
     let _ = 2.225_073_858_507_201_1e-308_f64;
+
+    // issue #7745
+    let _ = 1.000_000_000_000_001e-324_f64;
 }
diff --git a/tests/ui/excessive_precision.stderr b/tests/ui/excessive_precision.stderr
index c9418f73d98..42d9d4de193 100644
--- a/tests/ui/excessive_precision.stderr
+++ b/tests/ui/excessive_precision.stderr
@@ -84,5 +84,11 @@ error: float has excessive precision
 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
+error: float has excessive precision
+  --> $DIR/excessive_precision.rs:68:13
+   |
+LL |     let _ = 1.000_000_000_000_001e-324_f64;
+   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0_f64`
+
+error: aborting due to 15 previous errors