@@ -9,12 +9,12 @@ mod zero_prefixed_literal;
99
1010use clippy_utils:: diagnostics:: span_lint;
1111use clippy_utils:: source:: snippet_opt;
12- use rustc_ast:: ast:: { Expr , ExprKind , Generics , Lit , LitFloatType , LitIntType , LitKind , NodeId , Pat , PatKind } ;
12+ use rustc_ast:: ast:: { Expr , Generics , Lit , LitFloatType , LitIntType , LitKind , NodeId , Pat , PatKind } ;
1313use rustc_ast:: visit:: FnKind ;
1414use rustc_data_structures:: fx:: FxHashMap ;
1515use rustc_lint:: { EarlyContext , EarlyLintPass } ;
1616use rustc_middle:: lint:: in_external_macro;
17- use rustc_session:: { declare_tool_lint , impl_lint_pass } ;
17+ use rustc_session:: { declare_lint_pass , declare_tool_lint } ;
1818use rustc_span:: source_map:: Span ;
1919
2020declare_clippy_lint ! {
@@ -113,35 +113,20 @@ declare_clippy_lint! {
113113
114114declare_clippy_lint ! {
115115 /// ### What it does
116- /// If `literal-suffix-stylle` = "separated", warns literal suffixes that are not separated by an
117- /// underscore
118- /// e.g `123i32`
116+ /// Warns if literal suffixes are not separated by an
117+ /// underscore.
119118 ///
120- /// If `literal-suffix-style` = "unseparated", warns literal suffixes that are separated by an
121- /// underscore
122- /// e.g. `123_i32`
123- ///
124- /// else, any style of literal_suffix is allowed
119+ /// ### Why is this bad?
120+ /// It is much less readable.
125121 ///
126122 /// ### Example
127- ///
128- /// #### "separated"
129123 /// ```rust
130124 /// // Bad
131125 /// let y = 123832i32;
132126 ///
133127 /// // Good
134128 /// let y = 123832_i32;
135129 /// ```
136- ///
137- /// #### "unseparated"
138- /// ```rust
139- /// // Bad
140- /// let y = 123832_i32;
141- ///
142- /// // Good
143- /// let y = 123832i32;
144- /// ```
145130 pub UNSEPARATED_LITERAL_SUFFIX ,
146131 restriction,
147132 "literals whose suffix is not separated by an underscore"
@@ -269,12 +254,7 @@ declare_clippy_lint! {
269254 "tuple patterns with a wildcard pattern (`_`) is next to a rest pattern (`..`)"
270255}
271256
272- #[ allow( clippy:: module_name_repetitions) ]
273- pub struct MiscEarlyLints {
274- literal_suffix_style : Option < LiteralSuffixStyle > ,
275- }
276-
277- impl_lint_pass ! ( MiscEarlyLints => [
257+ declare_lint_pass ! ( MiscEarlyLints => [
278258 UNNEEDED_FIELD_PATTERN ,
279259 DUPLICATE_UNDERSCORE_ARGUMENT ,
280260 DOUBLE_NEG ,
@@ -330,29 +310,12 @@ impl EarlyLintPass for MiscEarlyLints {
330310 if in_external_macro ( cx. sess , expr. span ) {
331311 return ;
332312 }
333-
334- if let ExprKind :: Lit ( ref lit) = expr. kind {
335- self . check_lit ( cx, lit) ;
336- }
337313 double_neg:: check ( cx, expr) ;
338314 }
339315}
340316
341317impl MiscEarlyLints {
342- pub fn new ( suffix_style : Option < String > ) -> Self {
343- let literal_suffix_style = match suffix_style {
344- Some ( style) => match style. as_str ( ) {
345- "unseparated" => Some ( LiteralSuffixStyle :: Unseparated ) ,
346- "separated" => Some ( LiteralSuffixStyle :: Separated ) ,
347- _ => None ,
348- } ,
349- _ => None ,
350- } ;
351-
352- Self { literal_suffix_style }
353- }
354-
355- fn check_lit ( & self , cx : & EarlyContext < ' _ > , lit : & Lit ) {
318+ fn check_lit ( cx : & EarlyContext < ' _ > , lit : & Lit ) {
356319 // We test if first character in snippet is a number, because the snippet could be an expansion
357320 // from a built-in macro like `line!()` or a proc-macro like `#[wasm_bindgen]`.
358321 // Note that this check also covers special case that `line!()` is eagerly expanded by compiler.
@@ -369,7 +332,7 @@ impl MiscEarlyLints {
369332 LitIntType :: Unsigned ( ty) => ty. name_str ( ) ,
370333 LitIntType :: Unsuffixed => "" ,
371334 } ;
372- unseparated_literal_suffix:: check ( cx, lit, & lit_snip, suffix, "integer" , self . literal_suffix_style ) ;
335+ unseparated_literal_suffix:: check ( cx, lit, & lit_snip, suffix, "integer" ) ;
373336 if lit_snip. starts_with ( "0x" ) {
374337 mixed_case_hex_literals:: check ( cx, lit, suffix, & lit_snip) ;
375338 } else if lit_snip. starts_with ( "0b" ) || lit_snip. starts_with ( "0o" ) {
@@ -379,13 +342,7 @@ impl MiscEarlyLints {
379342 }
380343 } else if let LitKind :: Float ( _, LitFloatType :: Suffixed ( float_ty) ) = lit. kind {
381344 let suffix = float_ty. name_str ( ) ;
382- unseparated_literal_suffix:: check ( cx, lit, & lit_snip, suffix, "float" , self . literal_suffix_style ) ;
345+ unseparated_literal_suffix:: check ( cx, lit, & lit_snip, suffix, "float" ) ;
383346 }
384347 }
385348}
386-
387- #[ derive( Copy , Clone ) ]
388- enum LiteralSuffixStyle {
389- Unseparated ,
390- Separated ,
391- }
0 commit comments