@@ -134,7 +134,7 @@ impl<'a> DigitInfo<'a> {
134134
135135 let mut last_d = '\0' ;
136136 for ( d_idx, d) in sans_prefix. char_indices ( ) {
137- if !float && ( d == 'i' || d == 'u' ) || float && d == 'f' {
137+ if !float && ( d == 'i' || d == 'u' ) || float && ( d == 'f' || d == 'e' || d == 'E' ) {
138138 let suffix_start = if last_d == '_' { d_idx - 1 } else { d_idx } ;
139139 let ( digits, suffix) = sans_prefix. split_at ( suffix_start) ;
140140 return Self {
@@ -285,60 +285,64 @@ impl EarlyLintPass for LiteralDigitGrouping {
285285
286286impl LiteralDigitGrouping {
287287 fn check_lit ( & self , cx : & EarlyContext , lit : & Lit ) {
288- // Lint integral literals.
289- if_chain ! {
290- if let LitKind :: Int ( ..) = lit. node;
291- if let Some ( src) = snippet_opt( cx, lit. span) ;
292- if let Some ( firstch) = src. chars( ) . next( ) ;
293- if char :: to_digit( firstch, 10 ) . is_some( ) ;
294- then {
295- let digit_info = DigitInfo :: new( & src, false ) ;
296- let _ = Self :: do_lint( digit_info. digits) . map_err( |warning_type| {
297- warning_type. display( & digit_info. grouping_hint( ) , cx, & lit. span)
298- } ) ;
299- }
300- }
301-
302- // Lint floating-point literals.
303- if_chain ! {
304- if let LitKind :: Float ( ..) = lit. node;
305- if let Some ( src) = snippet_opt( cx, lit. span) ;
306- if let Some ( firstch) = src. chars( ) . next( ) ;
307- if char :: to_digit( firstch, 10 ) . is_some( ) ;
308- then {
309- let digit_info = DigitInfo :: new( & src, true ) ;
310- // Separate digits into integral and fractional parts.
311- let parts: Vec <& str > = digit_info
312- . digits
313- . split_terminator( '.' )
314- . collect( ) ;
315-
316- // Lint integral and fractional parts separately, and then check consistency of digit
317- // groups if both pass.
318- let _ = Self :: do_lint( parts[ 0 ] )
319- . map( |integral_group_size| {
320- if parts. len( ) > 1 {
321- // Lint the fractional part of literal just like integral part, but reversed.
322- let fractional_part = & parts[ 1 ] . chars( ) . rev( ) . collect:: <String >( ) ;
323- let _ = Self :: do_lint( fractional_part)
324- . map( |fractional_group_size| {
325- let consistent = Self :: parts_consistent( integral_group_size,
326- fractional_group_size,
327- parts[ 0 ] . len( ) ,
328- parts[ 1 ] . len( ) ) ;
329- if !consistent {
330- WarningType :: InconsistentDigitGrouping . display( & digit_info. grouping_hint( ) ,
331- cx,
332- & lit. span) ;
333- }
334- } )
335- . map_err( |warning_type| warning_type. display( & digit_info. grouping_hint( ) ,
336- cx,
337- & lit. span) ) ;
338- }
339- } )
340- . map_err( |warning_type| warning_type. display( & digit_info. grouping_hint( ) , cx, & lit. span) ) ;
341- }
288+ match lit. node {
289+ LitKind :: Int ( ..) => {
290+ // Lint integral literals.
291+ if_chain ! {
292+ if let Some ( src) = snippet_opt( cx, lit. span) ;
293+ if let Some ( firstch) = src. chars( ) . next( ) ;
294+ if char :: to_digit( firstch, 10 ) . is_some( ) ;
295+ then {
296+ let digit_info = DigitInfo :: new( & src, false ) ;
297+ let _ = Self :: do_lint( digit_info. digits) . map_err( |warning_type| {
298+ warning_type. display( & digit_info. grouping_hint( ) , cx, & lit. span)
299+ } ) ;
300+ }
301+ }
302+ } ,
303+ LitKind :: Float ( ..) | LitKind :: FloatUnsuffixed ( ..) => {
304+ // Lint floating-point literals.
305+ if_chain ! {
306+ if let Some ( src) = snippet_opt( cx, lit. span) ;
307+ if let Some ( firstch) = src. chars( ) . next( ) ;
308+ if char :: to_digit( firstch, 10 ) . is_some( ) ;
309+ then {
310+ let digit_info = DigitInfo :: new( & src, true ) ;
311+ // Separate digits into integral and fractional parts.
312+ let parts: Vec <& str > = digit_info
313+ . digits
314+ . split_terminator( '.' )
315+ . collect( ) ;
316+
317+ // Lint integral and fractional parts separately, and then check consistency of digit
318+ // groups if both pass.
319+ let _ = Self :: do_lint( parts[ 0 ] )
320+ . map( |integral_group_size| {
321+ if parts. len( ) > 1 {
322+ // Lint the fractional part of literal just like integral part, but reversed.
323+ let fractional_part = & parts[ 1 ] . chars( ) . rev( ) . collect:: <String >( ) ;
324+ let _ = Self :: do_lint( fractional_part)
325+ . map( |fractional_group_size| {
326+ let consistent = Self :: parts_consistent( integral_group_size,
327+ fractional_group_size,
328+ parts[ 0 ] . len( ) ,
329+ parts[ 1 ] . len( ) ) ;
330+ if !consistent {
331+ WarningType :: InconsistentDigitGrouping . display( & digit_info. grouping_hint( ) ,
332+ cx,
333+ & lit. span) ;
334+ }
335+ } )
336+ . map_err( |warning_type| warning_type. display( & digit_info. grouping_hint( ) ,
337+ cx,
338+ & lit. span) ) ;
339+ }
340+ } )
341+ . map_err( |warning_type| warning_type. display( & digit_info. grouping_hint( ) , cx, & lit. span) ) ;
342+ }
343+ }
344+ } ,
345+ _ => ( ) ,
342346 }
343347 }
344348
0 commit comments