Skip to content

Commit 2e8946a

Browse files
author
Michael Wright
committed
literal representation restructure 3
Move suffix check into `check_lit` so that it isn't done repeatedly.
1 parent 2dbd34f commit 2e8946a

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

clippy_lints/src/literal_representation.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,15 @@ impl LiteralDigitGrouping {
372372
};
373373

374374
let result = (|| {
375+
if let Some(suffix) = digit_info.suffix {
376+
if is_mistyped_suffix(suffix) {
377+
return Err(WarningType::MistypedLiteralSuffix);
378+
}
379+
}
380+
375381
match lit.kind {
376382
LitKind::Int(..) => {
377-
Self::do_lint(digit_info.digits, digit_info.suffix, in_macro)?;
383+
Self::do_lint(digit_info.digits, in_macro)?;
378384
},
379385
LitKind::Float(..) => {
380386
// Separate digits into integral and fractional parts.
@@ -385,11 +391,11 @@ impl LiteralDigitGrouping {
385391

386392
// Lint integral and fractional parts separately, and then check consistency of digit
387393
// groups if both pass.
388-
let integral_group_size = Self::do_lint(parts[0], digit_info.suffix, in_macro)?;
394+
let integral_group_size = Self::do_lint(parts[0], in_macro)?;
389395
if parts.len() > 1 {
390396
// Lint the fractional part of literal just like integral part, but reversed.
391397
let fractional_part = &parts[1].chars().rev().collect::<String>();
392-
let fractional_group_size = Self::do_lint(fractional_part, None, in_macro)?;
398+
let fractional_group_size = Self::do_lint(fractional_part, in_macro)?;
393399
let consistent = Self::parts_consistent(integral_group_size,
394400
fractional_group_size,
395401
parts[0].len(),
@@ -432,12 +438,7 @@ impl LiteralDigitGrouping {
432438

433439
/// Performs lint on `digits` (no decimal point) and returns the group
434440
/// size on success or `WarningType` when emitting a warning.
435-
fn do_lint(digits: &str, suffix: Option<&str>, in_macro: bool) -> Result<usize, WarningType> {
436-
if let Some(suffix) = suffix {
437-
if is_mistyped_suffix(suffix) {
438-
return Err(WarningType::MistypedLiteralSuffix);
439-
}
440-
}
441+
fn do_lint(digits: &str, in_macro: bool) -> Result<usize, WarningType> {
441442
// Grab underscore indices with respect to the units digit.
442443
let underscore_positions: Vec<usize> = digits
443444
.chars()

0 commit comments

Comments
 (0)