@@ -9,12 +9,12 @@ mod zero_prefixed_literal;
9
9
10
10
use clippy_utils:: diagnostics:: span_lint;
11
11
use 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 } ;
13
13
use rustc_ast:: visit:: FnKind ;
14
14
use rustc_data_structures:: fx:: FxHashMap ;
15
15
use rustc_lint:: { EarlyContext , EarlyLintPass } ;
16
16
use 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 } ;
18
18
use rustc_span:: source_map:: Span ;
19
19
20
20
declare_clippy_lint ! {
@@ -113,35 +113,20 @@ declare_clippy_lint! {
113
113
114
114
declare_clippy_lint ! {
115
115
/// ### 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.
119
118
///
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.
125
121
///
126
122
/// ### Example
127
- ///
128
- /// #### "separated"
129
123
/// ```rust
130
124
/// // Bad
131
125
/// let y = 123832i32;
132
126
///
133
127
/// // Good
134
128
/// let y = 123832_i32;
135
129
/// ```
136
- ///
137
- /// #### "unseparated"
138
- /// ```rust
139
- /// // Bad
140
- /// let y = 123832_i32;
141
- ///
142
- /// // Good
143
- /// let y = 123832i32;
144
- /// ```
145
130
pub UNSEPARATED_LITERAL_SUFFIX ,
146
131
restriction,
147
132
"literals whose suffix is not separated by an underscore"
@@ -269,12 +254,7 @@ declare_clippy_lint! {
269
254
"tuple patterns with a wildcard pattern (`_`) is next to a rest pattern (`..`)"
270
255
}
271
256
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 => [
278
258
UNNEEDED_FIELD_PATTERN ,
279
259
DUPLICATE_UNDERSCORE_ARGUMENT ,
280
260
DOUBLE_NEG ,
@@ -330,29 +310,12 @@ impl EarlyLintPass for MiscEarlyLints {
330
310
if in_external_macro ( cx. sess , expr. span ) {
331
311
return ;
332
312
}
333
-
334
- if let ExprKind :: Lit ( ref lit) = expr. kind {
335
- self . check_lit ( cx, lit) ;
336
- }
337
313
double_neg:: check ( cx, expr) ;
338
314
}
339
315
}
340
316
341
317
impl 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 ) {
356
319
// We test if first character in snippet is a number, because the snippet could be an expansion
357
320
// from a built-in macro like `line!()` or a proc-macro like `#[wasm_bindgen]`.
358
321
// Note that this check also covers special case that `line!()` is eagerly expanded by compiler.
@@ -369,7 +332,7 @@ impl MiscEarlyLints {
369
332
LitIntType :: Unsigned ( ty) => ty. name_str ( ) ,
370
333
LitIntType :: Unsuffixed => "" ,
371
334
} ;
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" ) ;
373
336
if lit_snip. starts_with ( "0x" ) {
374
337
mixed_case_hex_literals:: check ( cx, lit, suffix, & lit_snip) ;
375
338
} else if lit_snip. starts_with ( "0b" ) || lit_snip. starts_with ( "0o" ) {
@@ -379,13 +342,7 @@ impl MiscEarlyLints {
379
342
}
380
343
} else if let LitKind :: Float ( _, LitFloatType :: Suffixed ( float_ty) ) = lit. kind {
381
344
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" ) ;
383
346
}
384
347
}
385
348
}
386
-
387
- #[ derive( Copy , Clone ) ]
388
- enum LiteralSuffixStyle {
389
- Unseparated ,
390
- Separated ,
391
- }
0 commit comments