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 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::diagnostics::{span_lint, span_lint_and_help, span_lint_and_sugg, span_lint_and_then};
|
||||||
use clippy_utils::source::snippet_opt;
|
use clippy_utils::source::snippet_opt;
|
||||||
use rustc_ast::ast::{
|
use rustc_ast::ast::{
|
||||||
BindingMode, Expr, ExprKind, Generics, Lit, LitFloatType, LitIntType, LitKind, Mutability, NodeId, Pat, PatKind,
|
BindingMode, Expr, Generics, Lit, LitFloatType, LitIntType, LitKind, Mutability, NodeId, Pat, PatKind,
|
||||||
UnOp,
|
|
||||||
};
|
};
|
||||||
use rustc_ast::visit::FnKind;
|
use rustc_ast::visit::FnKind;
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
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) {
|
if in_external_macro(cx.sess(), expr.span) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
match expr.kind {
|
double_neg::check(cx, expr)
|
||||||
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),
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user