From 2e8946a6de9dba222e1af8419bbb6f739b63eeea Mon Sep 17 00:00:00 2001 From: Michael Wright Date: Wed, 13 Nov 2019 08:27:14 +0200 Subject: [PATCH] literal representation restructure 3 Move suffix check into `check_lit` so that it isn't done repeatedly. --- clippy_lints/src/literal_representation.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/clippy_lints/src/literal_representation.rs b/clippy_lints/src/literal_representation.rs index 6ea962f0ac365..5b234948f2414 100644 --- a/clippy_lints/src/literal_representation.rs +++ b/clippy_lints/src/literal_representation.rs @@ -372,9 +372,15 @@ impl LiteralDigitGrouping { }; let result = (|| { + if let Some(suffix) = digit_info.suffix { + if is_mistyped_suffix(suffix) { + return Err(WarningType::MistypedLiteralSuffix); + } + } + match lit.kind { LitKind::Int(..) => { - Self::do_lint(digit_info.digits, digit_info.suffix, in_macro)?; + Self::do_lint(digit_info.digits, in_macro)?; }, LitKind::Float(..) => { // Separate digits into integral and fractional parts. @@ -385,11 +391,11 @@ impl LiteralDigitGrouping { // Lint integral and fractional parts separately, and then check consistency of digit // groups if both pass. - let integral_group_size = Self::do_lint(parts[0], digit_info.suffix, in_macro)?; + let integral_group_size = Self::do_lint(parts[0], in_macro)?; if parts.len() > 1 { // Lint the fractional part of literal just like integral part, but reversed. let fractional_part = &parts[1].chars().rev().collect::(); - let fractional_group_size = Self::do_lint(fractional_part, None, in_macro)?; + let fractional_group_size = Self::do_lint(fractional_part, in_macro)?; let consistent = Self::parts_consistent(integral_group_size, fractional_group_size, parts[0].len(), @@ -432,12 +438,7 @@ impl LiteralDigitGrouping { /// Performs lint on `digits` (no decimal point) and returns the group /// size on success or `WarningType` when emitting a warning. - fn do_lint(digits: &str, suffix: Option<&str>, in_macro: bool) -> Result { - if let Some(suffix) = suffix { - if is_mistyped_suffix(suffix) { - return Err(WarningType::MistypedLiteralSuffix); - } - } + fn do_lint(digits: &str, in_macro: bool) -> Result { // Grab underscore indices with respect to the units digit. let underscore_positions: Vec = digits .chars()