]> git.lizzy.rs Git - rust.git/commitdiff
tmp progress
authorMaxwell Anderson <maxwell.brayden.anderson@gmail.com>
Fri, 12 Oct 2018 04:15:01 +0000 (22:15 -0600)
committerMaxwell Anderson <maxwell.brayden.anderson@gmail.com>
Fri, 12 Oct 2018 04:15:01 +0000 (22:15 -0600)
clippy_lints/src/literal_representation.rs
tests/ui/literals.rs

index a123415cca9d797591661272f6609f1e4e5361a0..2d64a24a79be1ae28bd5a182ab5cfe0f88ef3880 100644 (file)
@@ -173,8 +173,10 @@ impl<'a> DigitInfo<'a> {
             } else {
                 d_idx
             };
-            if float && (d == 'f' || d == 'e' || d == 'E') ||
-                !float && (d == 'i' || d == 'u' || is_possible_suffix_index(&sans_prefix, suffix_start, len)) {
+            if float && ((is_possible_float_suffix_index(&sans_prefix, suffix_start, len)) ||
+                (d == 'f' || d == 'e' || d == 'E')) ||
+                !float && (d == 'i' || d == 'u' ||
+                is_possible_suffix_index(&sans_prefix, suffix_start, len)) {
                     let (digits, suffix) = sans_prefix.split_at(suffix_start);
                     return Self {
                         digits,
@@ -248,6 +250,9 @@ impl<'a> DigitInfo<'a> {
                 hint = format!("{:0>4}{}", &hint[..nb_digits_to_fill], &hint[nb_digits_to_fill..]);
             }
             let suffix_hint = match self.suffix {
+                Some(suffix) if is_mistyped_float_suffix(suffix) && self.digits.contains(".") => {
+                    format!("_f{}", &suffix[1..])
+                },
                 Some(suffix) if is_mistyped_suffix(suffix) => {
                     format!("_i{}", &suffix[1..])
                 },
@@ -572,3 +577,12 @@ fn is_possible_suffix_index(lit: &str, idx: usize, len: usize) -> bool {
     ((len > 3 && idx == len - 3) || (len > 2 && idx == len - 2)) &&
         is_mistyped_suffix(lit.split_at(idx).1)
 }
+
+fn is_mistyped_float_suffix(suffix: &str) -> bool {
+    ["_32", "_64"].contains(&suffix)
+}
+
+fn is_possible_float_suffix_index(lit: &str, idx: usize, len: usize) -> bool {
+    ((len > 3 && idx == len - 3) || (len > 2 && idx == len - 2)) &&
+        is_mistyped_float_suffix(lit.split_at(idx).1)
+}
index 3c1dcf09af2bb7ff60f489f75a3e442032d5ce8c..39d9f3f0e44c1f9107d38601039a7ee1845338b9 100644 (file)
@@ -64,4 +64,7 @@ fn main() {
     let fail21 = 4___16;
     let fail22 = 3__4___23;
     let fail23 = 3__16___23;
+
+    //let fail24 = 1E2_32;
+    let fail25 = 1.2_32;
 }