Skip to content

Commit 2d964b2

Browse files
committed
Revert "Add style configuration for unseparated_literal_suffix"
This reverts commit 87bb815baf78d122805ab8dc6c0251d380825a5b.
1 parent cfa8776 commit 2d964b2

File tree

5 files changed

+38
-115
lines changed

5 files changed

+38
-115
lines changed

clippy_lints/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
435435
store.register_early_pass(|| Box::new(else_if_without_else::ElseIfWithoutElse));
436436
store.register_early_pass(|| Box::new(int_plus_one::IntPlusOne));
437437
store.register_early_pass(|| Box::new(formatting::Formatting));
438-
let literal_suffix_style = conf.literal_suffix_style.clone();
439-
store.register_early_pass(move || Box::new(misc_early::MiscEarlyLints::new(literal_suffix_style.clone())));
438+
store.register_early_pass(|| Box::new(misc_early::MiscEarlyLints));
440439
store.register_early_pass(|| Box::new(redundant_closure_call::RedundantClosureCall));
441440
store.register_late_pass(|| Box::new(redundant_closure_call::RedundantClosureCall));
442441
store.register_early_pass(|| Box::new(unused_unit::UnusedUnit));
Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
1+
use super::MiscEarlyLints;
12
use clippy_utils::diagnostics::span_lint;
23
use rustc_ast::ast::{Expr, ExprKind, UnOp};
34
use rustc_lint::EarlyContext;
45

56
use super::DOUBLE_NEG;
67

78
pub(super) fn check(cx: &EarlyContext<'_>, expr: &Expr) {
8-
if let ExprKind::Unary(UnOp::Neg, ref inner) = expr.kind {
9-
if let ExprKind::Unary(UnOp::Neg, _) = inner.kind {
10-
span_lint(
11-
cx,
12-
DOUBLE_NEG,
13-
expr.span,
14-
"`--x` could be misinterpreted as pre-decrement by C programmers, is usually a no-op",
15-
);
16-
}
9+
match expr.kind {
10+
ExprKind::Unary(UnOp::Neg, ref inner) => {
11+
if let ExprKind::Unary(UnOp::Neg, _) = inner.kind {
12+
span_lint(
13+
cx,
14+
DOUBLE_NEG,
15+
expr.span,
16+
"`--x` could be misinterpreted as pre-decrement by C programmers, is usually a no-op",
17+
);
18+
}
19+
},
20+
ExprKind::Lit(ref lit) => MiscEarlyLints::check_lit(cx, lit),
21+
_ => (),
1722
}
1823
}

clippy_lints/src/misc_early/mod.rs

Lines changed: 10 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ mod zero_prefixed_literal;
99

1010
use clippy_utils::diagnostics::span_lint;
1111
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};
1313
use rustc_ast::visit::FnKind;
1414
use rustc_data_structures::fx::FxHashMap;
1515
use rustc_lint::{EarlyContext, EarlyLintPass};
1616
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};
1818
use rustc_span::source_map::Span;
1919

2020
declare_clippy_lint! {
@@ -113,35 +113,20 @@ declare_clippy_lint! {
113113

114114
declare_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

341317
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) {
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-
}

clippy_lints/src/misc_early/unseparated_literal_suffix.rs

Lines changed: 13 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,54 +3,24 @@ use rustc_ast::ast::Lit;
33
use rustc_errors::Applicability;
44
use rustc_lint::EarlyContext;
55

6-
use super::{LiteralSuffixStyle, UNSEPARATED_LITERAL_SUFFIX};
6+
use super::UNSEPARATED_LITERAL_SUFFIX;
77

8-
pub(super) fn check(
9-
cx: &EarlyContext<'_>,
10-
lit: &Lit,
11-
lit_snip: &str,
12-
suffix: &str,
13-
sugg_type: &str,
14-
style_opt: Option<LiteralSuffixStyle>,
15-
) {
16-
let style = if let Some(suffix_style) = style_opt {
17-
suffix_style
18-
} else {
19-
return;
20-
};
8+
pub(super) fn check(cx: &EarlyContext<'_>, lit: &Lit, lit_snip: &str, suffix: &str, sugg_type: &str) {
219
let maybe_last_sep_idx = if let Some(val) = lit_snip.len().checked_sub(suffix.len() + 1) {
2210
val
2311
} else {
2412
return; // It's useless so shouldn't lint.
2513
};
26-
27-
if suffix.is_empty() {
28-
return;
29-
}
30-
31-
match style {
32-
LiteralSuffixStyle::Separated if lit_snip.as_bytes()[maybe_last_sep_idx] != b'_' => {
33-
span_lint_and_sugg(
34-
cx,
35-
UNSEPARATED_LITERAL_SUFFIX,
36-
lit.span,
37-
&format!("{} type suffix should be separated by an underscore", sugg_type),
38-
"add an underscore",
39-
format!("{}_{}", &lit_snip[..=maybe_last_sep_idx], suffix),
40-
Applicability::MachineApplicable,
41-
);
42-
},
43-
LiteralSuffixStyle::Unseparated if lit_snip.as_bytes()[maybe_last_sep_idx] == b'_' => {
44-
span_lint_and_sugg(
45-
cx,
46-
UNSEPARATED_LITERAL_SUFFIX,
47-
lit.span,
48-
&format!("{} type suffix should not be separated by an underscore", sugg_type),
49-
"remove the underscore",
50-
lit_snip[..=maybe_last_sep_idx].to_string(),
51-
Applicability::MachineApplicable,
52-
);
53-
},
54-
_ => (),
14+
// Do not lint when literal is unsuffixed.
15+
if !suffix.is_empty() && lit_snip.as_bytes()[maybe_last_sep_idx] != b'_' {
16+
span_lint_and_sugg(
17+
cx,
18+
UNSEPARATED_LITERAL_SUFFIX,
19+
lit.span,
20+
&format!("{} type suffix should be separated by an underscore", sugg_type),
21+
"add an underscore",
22+
format!("{}_{}", &lit_snip[..=maybe_last_sep_idx], suffix),
23+
Applicability::MachineApplicable,
24+
);
5525
}
5626
}

clippy_lints/src/utils/conf.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -288,14 +288,6 @@ define_Conf! {
288288
///
289289
/// Whether to apply the raw pointer heuristic to determine if a type is `Send`.
290290
(enable_raw_pointer_heuristic_for_send: bool = true),
291-
/// Lint: UNSEPARATED_LITERAL_SUFFIX
292-
///
293-
/// Configure a specific style for writing literal suffix.
294-
/// Possible Options:
295-
/// - "unseparated" : enforce writing prefix without underscore `_`
296-
/// - "separated" : enforce writing prefix with underscore `_`
297-
/// - None : no style preference
298-
(literal_suffix_style: Option<String> = None),
299291
}
300292

301293
/// Search for the configuration file.

0 commit comments

Comments
 (0)