Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 55af0ce

Browse files
committed
move double_neg to its own module
1 parent 64eb18e commit 55af0ce

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
use super::MiscEarlyLints;
2+
use clippy_utils::diagnostics::span_lint;
3+
use rustc_ast::ast::{Expr, ExprKind, UnOp};
4+
use rustc_lint::EarlyContext;
5+
6+
use super::DOUBLE_NEG;
7+
8+
pub(super) fn check(cx: &EarlyContext<'_>, expr: &Expr) {
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+
_ => (),
22+
}
23+
}

clippy_lints/src/misc_early/mod.rs

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
mod builtin_type_shadow;
2+
mod double_neg;
23

34
use clippy_utils::diagnostics::{span_lint, span_lint_and_help, span_lint_and_sugg, span_lint_and_then};
45
use clippy_utils::source::snippet_opt;
56
use rustc_ast::ast::{
6-
BindingMode, Expr, ExprKind, Generics, Lit, LitFloatType, LitIntType, LitKind, Mutability, NodeId, Pat, PatKind,
7-
UnOp,
7+
BindingMode, Expr, Generics, Lit, LitFloatType, LitIntType, LitKind, Mutability, NodeId, Pat, PatKind,
88
};
99
use rustc_ast::visit::FnKind;
1010
use rustc_data_structures::fx::FxHashMap;
@@ -393,20 +393,7 @@ impl EarlyLintPass for MiscEarlyLints {
393393
if in_external_macro(cx.sess(), expr.span) {
394394
return;
395395
}
396-
match expr.kind {
397-
ExprKind::Unary(UnOp::Neg, ref inner) => {
398-
if let ExprKind::Unary(UnOp::Neg, _) = inner.kind {
399-
span_lint(
400-
cx,
401-
DOUBLE_NEG,
402-
expr.span,
403-
"`--x` could be misinterpreted as pre-decrement by C programmers, is usually a no-op",
404-
);
405-
}
406-
},
407-
ExprKind::Lit(ref lit) => Self::check_lit(cx, lit),
408-
_ => (),
409-
}
396+
double_neg::check(cx, expr)
410397
}
411398
}
412399

0 commit comments

Comments
 (0)