move double_neg to its own module
This commit is contained in:
parent
64eb18e675
commit
55af0cee15
23
clippy_lints/src/misc_early/double_neg.rs
Normal file
23
clippy_lints/src/misc_early/double_neg.rs
Normal file
@ -0,0 +1,23 @@
|
||||
use super::MiscEarlyLints;
|
||||
use clippy_utils::diagnostics::span_lint;
|
||||
use rustc_ast::ast::{Expr, ExprKind, UnOp};
|
||||
use rustc_lint::EarlyContext;
|
||||
|
||||
use super::DOUBLE_NEG;
|
||||
|
||||
pub(super) fn check(cx: &EarlyContext<'_>, expr: &Expr) {
|
||||
match expr.kind {
|
||||
ExprKind::Unary(UnOp::Neg, ref inner) => {
|
||||
if let ExprKind::Unary(UnOp::Neg, _) = inner.kind {
|
||||
span_lint(
|
||||
cx,
|
||||
DOUBLE_NEG,
|
||||
expr.span,
|
||||
"`--x` could be misinterpreted as pre-decrement by C programmers, is usually a no-op",
|
||||
);
|
||||
}
|
||||
},
|
||||
ExprKind::Lit(ref lit) => MiscEarlyLints::check_lit(cx, lit),
|
||||
_ => (),
|
||||
}
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
mod builtin_type_shadow;
|
||||
mod double_neg;
|
||||
|
||||
use clippy_utils::diagnostics::{span_lint, span_lint_and_help, span_lint_and_sugg, span_lint_and_then};
|
||||
use clippy_utils::source::snippet_opt;
|
||||
use rustc_ast::ast::{
|
||||
BindingMode, Expr, ExprKind, Generics, Lit, LitFloatType, LitIntType, LitKind, Mutability, NodeId, Pat, PatKind,
|
||||
UnOp,
|
||||
BindingMode, Expr, Generics, Lit, LitFloatType, LitIntType, LitKind, Mutability, NodeId, Pat, PatKind,
|
||||
};
|
||||
use rustc_ast::visit::FnKind;
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
@ -393,20 +393,7 @@ fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) {
|
||||
if in_external_macro(cx.sess(), expr.span) {
|
||||
return;
|
||||
}
|
||||
match expr.kind {
|
||||
ExprKind::Unary(UnOp::Neg, ref inner) => {
|
||||
if let ExprKind::Unary(UnOp::Neg, _) = inner.kind {
|
||||
span_lint(
|
||||
cx,
|
||||
DOUBLE_NEG,
|
||||
expr.span,
|
||||
"`--x` could be misinterpreted as pre-decrement by C programmers, is usually a no-op",
|
||||
);
|
||||
}
|
||||
},
|
||||
ExprKind::Lit(ref lit) => Self::check_lit(cx, lit),
|
||||
_ => (),
|
||||
}
|
||||
double_neg::check(cx, expr)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user