]> 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 4a28c7dd9a04a3885251ef7ab44e7d5ea65aa7fe..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,8 +157,10 @@ 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 {
@@ -177,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 {