@@ -358,67 +358,63 @@ impl EarlyLintPass for LiteralDigitGrouping {
358
358
impl LiteralDigitGrouping {
359
359
fn check_lit ( cx : & EarlyContext < ' _ > , lit : & Lit ) {
360
360
let in_macro = in_macro ( lit. span ) ;
361
+
362
+ if_chain ! {
363
+ if let Some ( src) = snippet_opt( cx, lit. span) ;
364
+ if let Some ( firstch) = src. chars( ) . next( ) ;
365
+ if char :: is_digit( firstch, 10 ) ;
366
+ then {
367
+
368
+
361
369
match lit. kind {
362
370
LitKind :: Int ( ..) => {
363
371
// Lint integral literals.
364
- if_chain ! {
365
- if let Some ( src) = snippet_opt( cx, lit. span) ;
366
- if let Some ( firstch) = src. chars( ) . next( ) ;
367
- if char :: is_digit( firstch, 10 ) ;
368
- then {
369
- let digit_info = DigitInfo :: new( & src, false ) ;
370
- let _ = Self :: do_lint( digit_info. digits, digit_info. suffix, in_macro) . map_err( |warning_type| {
371
- warning_type. display( & digit_info. grouping_hint( ) , cx, lit. span)
372
- } ) ;
373
- }
374
- }
372
+ let digit_info = DigitInfo :: new( & src, false ) ;
373
+ let _ = Self :: do_lint( digit_info. digits, digit_info. suffix, in_macro) . map_err( |warning_type| {
374
+ warning_type. display( & digit_info. grouping_hint( ) , cx, lit. span)
375
+ } ) ;
375
376
} ,
376
377
LitKind :: Float ( ..) => {
377
378
// Lint floating-point literals.
378
- if_chain ! {
379
- if let Some ( src) = snippet_opt( cx, lit. span) ;
380
- if let Some ( firstch) = src. chars( ) . next( ) ;
381
- if char :: is_digit( firstch, 10 ) ;
382
- then {
383
- let digit_info = DigitInfo :: new( & src, true ) ;
384
- // Separate digits into integral and fractional parts.
385
- let parts: Vec <& str > = digit_info
386
- . digits
387
- . split_terminator( '.' )
388
- . collect( ) ;
389
-
390
- // Lint integral and fractional parts separately, and then check consistency of digit
391
- // groups if both pass.
392
- let _ = Self :: do_lint( parts[ 0 ] , digit_info. suffix, in_macro)
393
- . map( |integral_group_size| {
394
- if parts. len( ) > 1 {
395
- // Lint the fractional part of literal just like integral part, but reversed.
396
- let fractional_part = & parts[ 1 ] . chars( ) . rev( ) . collect:: <String >( ) ;
397
- let _ = Self :: do_lint( fractional_part, None , in_macro)
398
- . map( |fractional_group_size| {
399
- let consistent = Self :: parts_consistent( integral_group_size,
400
- fractional_group_size,
401
- parts[ 0 ] . len( ) ,
402
- parts[ 1 ] . len( ) ) ;
403
- if !consistent {
404
- WarningType :: InconsistentDigitGrouping . display(
405
- & digit_info. grouping_hint( ) ,
406
- cx,
407
- lit. span,
408
- ) ;
409
- }
410
- } )
411
- . map_err( |warning_type| warning_type. display( & digit_info. grouping_hint( ) ,
412
- cx,
413
- lit. span) ) ;
414
- }
415
- } )
416
- . map_err( |warning_type| warning_type. display( & digit_info. grouping_hint( ) , cx, lit. span) ) ;
417
- }
418
- }
379
+ let digit_info = DigitInfo :: new( & src, true ) ;
380
+ // Separate digits into integral and fractional parts.
381
+ let parts: Vec <& str > = digit_info
382
+ . digits
383
+ . split_terminator( '.' )
384
+ . collect( ) ;
385
+
386
+ // Lint integral and fractional parts separately, and then check consistency of digit
387
+ // groups if both pass.
388
+ let _ = Self :: do_lint( parts[ 0 ] , digit_info. suffix, in_macro)
389
+ . map( |integral_group_size| {
390
+ if parts. len( ) > 1 {
391
+ // Lint the fractional part of literal just like integral part, but reversed.
392
+ let fractional_part = & parts[ 1 ] . chars( ) . rev( ) . collect:: <String >( ) ;
393
+ let _ = Self :: do_lint( fractional_part, None , in_macro)
394
+ . map( |fractional_group_size| {
395
+ let consistent = Self :: parts_consistent( integral_group_size,
396
+ fractional_group_size,
397
+ parts[ 0 ] . len( ) ,
398
+ parts[ 1 ] . len( ) ) ;
399
+ if !consistent {
400
+ WarningType :: InconsistentDigitGrouping . display(
401
+ & digit_info. grouping_hint( ) ,
402
+ cx,
403
+ lit. span,
404
+ ) ;
405
+ }
406
+ } )
407
+ . map_err( |warning_type| warning_type. display( & digit_info. grouping_hint( ) ,
408
+ cx,
409
+ lit. span) ) ;
410
+ }
411
+ } )
412
+ . map_err( |warning_type| warning_type. display( & digit_info. grouping_hint( ) , cx, lit. span) ) ;
419
413
} ,
420
414
_ => ( ) ,
421
415
}
416
+ }
417
+ }
422
418
}
423
419
424
420
/// Given the sizes of the digit groups of both integral and fractional
0 commit comments