@@ -7,12 +7,11 @@ mod unneeded_wildcard_pattern;
77mod unseparated_literal_suffix;
88mod zero_prefixed_literal;
99
10- use clippy_utils:: diagnostics:: { span_lint, span_lint_and_sugg } ;
10+ use clippy_utils:: diagnostics:: span_lint;
1111use clippy_utils:: source:: snippet_opt;
1212use rustc_ast:: ast:: { Expr , Generics , Lit , LitFloatType , LitIntType , LitKind , NodeId , Pat , PatKind } ;
1313use rustc_ast:: visit:: FnKind ;
1414use rustc_data_structures:: fx:: FxHashMap ;
15- use rustc_errors:: Applicability ;
1615use rustc_lint:: { EarlyContext , EarlyLintPass , LintContext } ;
1716use rustc_middle:: lint:: in_external_macro;
1817use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
@@ -333,34 +332,17 @@ impl MiscEarlyLints {
333332 LitIntType :: Unsigned ( ty) => ty. name_str ( ) ,
334333 LitIntType :: Unsuffixed => "" ,
335334 } ;
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" ) ;
355336 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)
357338 } else if lit_snip. starts_with ( "0b" ) || lit_snip. starts_with ( "0o" ) {
358339 /* nothing to do */
359340 } else if value != 0 && lit_snip. starts_with ( '0' ) {
360341 zero_prefixed_literal:: check ( cx, lit, lit_snip)
361342 }
362343 } 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" )
364346 }
365347 }
366348}
0 commit comments