diff options
| author | Takayuki <takoyaki0316@gmail.com> | 2021-05-04 17:20:22 +0900 |
|---|---|---|
| committer | Takayuki <takoyaki0316@gmail.com> | 2021-05-04 17:20:22 +0900 |
| commit | 55af0cee15cf5c85cbb50ef41eafb4498bde24e3 (patch) | |
| tree | 82b49265dae2b38cd96adf48f393e3d4cbb6447f | |
| parent | 64eb18e6759f4375d01d7e3352447ff6b4305184 (diff) | |
| download | rust-55af0cee15cf5c85cbb50ef41eafb4498bde24e3.tar.gz rust-55af0cee15cf5c85cbb50ef41eafb4498bde24e3.zip | |
move double_neg to its own module
| -rw-r--r-- | clippy_lints/src/misc_early/double_neg.rs | 23 | ||||
| -rw-r--r-- | clippy_lints/src/misc_early/mod.rs | 19 |
2 files changed, 26 insertions, 16 deletions
diff --git a/clippy_lints/src/misc_early/double_neg.rs b/clippy_lints/src/misc_early/double_neg.rs new file mode 100644 index 00000000000..6f65778e119 --- /dev/null +++ b/clippy_lints/src/misc_early/double_neg.rs @@ -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), + _ => (), + } +} diff --git a/clippy_lints/src/misc_early/mod.rs b/clippy_lints/src/misc_early/mod.rs index 94740093d3b..47cc87dfffb 100644 --- a/clippy_lints/src/misc_early/mod.rs +++ b/clippy_lints/src/misc_early/mod.rs @@ -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 @@ impl EarlyLintPass for MiscEarlyLints { 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) } } |
