]> git.lizzy.rs Git - rust.git/blobdiff - clippy_utils/src/numeric_literal.rs
Address internal lints
[rust.git] / clippy_utils / src / numeric_literal.rs
index 546706d51d7b597c3f6d03b90a1448152533d37b..68dd1b29845a570cc4f6b30af834414fc34d70c5 100644 (file)
@@ -74,7 +74,7 @@ pub fn new(lit: &'a str, suffix: Option<&'a str>, float: bool) -> Self {
         };
 
         // Grab part of the literal after prefix, if present.
-        let (prefix, mut sans_prefix) = if let Radix::Decimal = radix {
+        let (prefix, mut sans_prefix) = if radix == Radix::Decimal {
             (None, lit)
         } else {
             let (p, s) = lit.split_at(2);
@@ -157,11 +157,16 @@ pub fn format(&self) -> String {
         }
 
         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 {
+            if output.ends_with('.') {
+                output.push('0');
+            }
             output.push('_');
             output.push_str(suffix);
         }
@@ -174,6 +179,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 digits.clone().next() == Some('-') {
+            let _ = digits.next();
+            output.push('-');
+        }
+
         let first_group_size;
 
         if partial_group_first {