]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/arithmetic.rs
MutImmutable -> Immutable, MutMutable -> Mutable, CaptureClause -> CaptureBy
[rust.git] / clippy_lints / src / arithmetic.rs
index 416ec656e12a44bb5d1729f15e2c413c46ddb176..1cca897e73900b9eaa11fde39574f522d2585387 100644 (file)
@@ -2,7 +2,7 @@
 use crate::utils::span_lint;
 use rustc::hir;
 use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
-use rustc::{declare_tool_lint, lint_array};
+use rustc::{declare_tool_lint, impl_lint_pass};
 use syntax::source_map::Span;
 
 declare_clippy_lint! {
@@ -16,7 +16,8 @@
     ///
     /// **Example:**
     /// ```rust
-    /// a + 1
+    /// # let a = 0;
+    /// a + 1;
     /// ```
     pub INTEGER_ARITHMETIC,
     restriction,
@@ -33,7 +34,8 @@
     ///
     /// **Example:**
     /// ```rust
-    /// a + 1.0
+    /// # let a = 0.0;
+    /// a + 1.0;
     /// ```
     pub FLOAT_ARITHMETIC,
     restriction,
@@ -48,15 +50,7 @@ pub struct Arithmetic {
     const_span: Option<Span>,
 }
 
-impl LintPass for Arithmetic {
-    fn get_lints(&self) -> LintArray {
-        lint_array!(INTEGER_ARITHMETIC, FLOAT_ARITHMETIC)
-    }
-
-    fn name(&self) -> &'static str {
-        "Arithmetic"
-    }
-}
+impl_lint_pass!(Arithmetic => [INTEGER_ARITHMETIC, FLOAT_ARITHMETIC]);
 
 impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Arithmetic {
     fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
@@ -69,8 +63,8 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
                 return;
             }
         }
-        match &expr.node {
-            hir::ExprKind::Binary(op, l, r) => {
+        match &expr.kind {
+            hir::ExprKind::Binary(op, l, r) | hir::ExprKind::AssignOp(op, l, r) => {
                 match op.node {
                     hir::BinOpKind::And
                     | hir::BinOpKind::Or