From 9fad38dca913573c1b534addc37affdcc174de0b Mon Sep 17 00:00:00 2001 From: Maxwell Anderson Date: Thu, 11 Oct 2018 22:15:01 -0600 Subject: [PATCH] tmp progress --- clippy_lints/src/literal_representation.rs | 18 ++++++++++++++++-- tests/ui/literals.rs | 3 +++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/literal_representation.rs b/clippy_lints/src/literal_representation.rs index a123415cc..2d64a24a7 100644 --- a/clippy_lints/src/literal_representation.rs +++ b/clippy_lints/src/literal_representation.rs @@ -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) +} diff --git a/tests/ui/literals.rs b/tests/ui/literals.rs index 3c1dcf09a..39d9f3f0e 100644 --- a/tests/ui/literals.rs +++ b/tests/ui/literals.rs @@ -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; }