]> git.lizzy.rs Git - rust.git/blobdiff - clippy_utils/src/numeric_literal.rs
Merge commit '54a20a02ecd0e1352a871aa0990bcc8b8b03173e' into clippyup
[rust.git] / clippy_utils / src / numeric_literal.rs
index d02603d7702c7f3c6a8f7f48d30b29a027ff7e00..4a28c7dd9a04a3885251ef7ab44e7d5ea65aa7fe 100644 (file)
@@ -1,4 +1,5 @@
 use rustc_ast::ast::{Lit, LitFloatType, LitIntType, LitKind};
+use std::iter;
 
 #[derive(Debug, PartialEq, Copy, Clone)]
 pub enum Radix {
@@ -51,7 +52,7 @@ pub fn from_lit(src: &'a str, lit: &Lit) -> Option<NumericLiteral<'a>> {
 
     pub fn from_lit_kind(src: &'a str, lit_kind: &LitKind) -> Option<NumericLiteral<'a>> {
         if lit_kind.is_numeric() && src.chars().next().map_or(false, |c| c.is_digit(10)) {
-            let (unsuffixed, suffix) = split_suffix(&src, lit_kind);
+            let (unsuffixed, suffix) = split_suffix(src, lit_kind);
             let float = matches!(lit_kind, LitKind::Float(..));
             Some(NumericLiteral::new(unsuffixed, suffix, float))
         } else {
@@ -161,6 +162,9 @@ pub fn format(&self) -> String {
         }
 
         if let Some(suffix) = self.suffix {
+            if output.ends_with('.') {
+                output.push('0');
+            }
             output.push('_');
             output.push_str(suffix);
         }
@@ -192,7 +196,7 @@ pub fn group_digits(output: &mut String, input: &str, group_size: usize, partial
             }
         }
 
-        for (c, i) in digits.zip((0..group_size).cycle()) {
+        for (c, i) in iter::zip(digits, (0..group_size).cycle()) {
             if i == 0 {
                 output.push('_');
             }