@@ -7,12 +7,11 @@ mod unneeded_wildcard_pattern;
7
7
mod unseparated_literal_suffix;
8
8
mod zero_prefixed_literal;
9
9
10
- use clippy_utils:: diagnostics:: { span_lint, span_lint_and_sugg } ;
10
+ use clippy_utils:: diagnostics:: span_lint;
11
11
use clippy_utils:: source:: snippet_opt;
12
12
use rustc_ast:: ast:: { Expr , Generics , Lit , LitFloatType , LitIntType , LitKind , NodeId , Pat , PatKind } ;
13
13
use rustc_ast:: visit:: FnKind ;
14
14
use rustc_data_structures:: fx:: FxHashMap ;
15
- use rustc_errors:: Applicability ;
16
15
use rustc_lint:: { EarlyContext , EarlyLintPass , LintContext } ;
17
16
use rustc_middle:: lint:: in_external_macro;
18
17
use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
@@ -333,34 +332,17 @@ impl MiscEarlyLints {
333
332
LitIntType :: Unsigned ( ty) => ty. name_str ( ) ,
334
333
LitIntType :: Unsuffixed => "" ,
335
334
} ;
336
-
337
- let maybe_last_sep_idx = if let Some ( val) = lit_snip. len ( ) . checked_sub ( suffix. len ( ) + 1 ) {
338
- val
339
- } else {
340
- return ; // It's useless so shouldn't lint.
341
- } ;
342
- // Do not lint when literal is unsuffixed.
343
- if !suffix. is_empty ( ) && lit_snip. as_bytes ( ) [ maybe_last_sep_idx] != b'_' {
344
- span_lint_and_sugg (
345
- cx,
346
- UNSEPARATED_LITERAL_SUFFIX ,
347
- lit. span ,
348
- "integer type suffix should be separated by an underscore" ,
349
- "add an underscore" ,
350
- format ! ( "{}_{}" , & lit_snip[ ..=maybe_last_sep_idx] , suffix) ,
351
- Applicability :: MachineApplicable ,
352
- ) ;
353
- }
354
-
335
+ unseparated_literal_suffix:: check ( cx, lit, & lit_snip, suffix, "integer" ) ;
355
336
if lit_snip. starts_with ( "0x" ) {
356
- mixed_case_hex_literals:: check ( cx, lit, maybe_last_sep_idx , lit_snip)
337
+ mixed_case_hex_literals:: check ( cx, lit, suffix , lit_snip)
357
338
} else if lit_snip. starts_with ( "0b" ) || lit_snip. starts_with ( "0o" ) {
358
339
/* nothing to do */
359
340
} else if value != 0 && lit_snip. starts_with ( '0' ) {
360
341
zero_prefixed_literal:: check ( cx, lit, lit_snip)
361
342
}
362
343
} else if let LitKind :: Float ( _, LitFloatType :: Suffixed ( float_ty) ) = lit. kind {
363
- unseparated_literal_suffix:: check ( cx, lit, float_ty, lit_snip)
344
+ let suffix = float_ty. name_str ( ) ;
345
+ unseparated_literal_suffix:: check ( cx, lit, & lit_snip, suffix, "float" )
364
346
}
365
347
}
366
348
}
0 commit comments