]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/erasing_op.rs
Auto merge of #3946 - rchaser53:issue-3920, r=flip1995
[rust.git] / clippy_lints / src / erasing_op.rs
index ae6e078ddaefb0ab718a9689f2c4a4c28c92f61b..07909ef587fee27bd0675563a688bb6828520bfe 100644 (file)
@@ -1,25 +1,30 @@
-use consts::{constant_simple, Constant};
 use rustc::hir::*;
-use rustc::lint::*;
-use syntax::codemap::Span;
-use utils::{in_macro, span_lint};
+use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
+use rustc::{declare_tool_lint, lint_array};
+use syntax::source_map::Span;
+
+use crate::consts::{constant_simple, Constant};
+use crate::utils::{in_macro, span_lint};
 
-/// **What it does:** Checks for erasing operations, e.g. `x * 0`.
-///
-/// **Why is this bad?** The whole expression can be replaced by zero.
-/// This is most likely not the intended outcome and should probably be
-/// corrected
-///
-/// **Known problems:** None.
-///
-/// **Example:**
-/// ```rust
-/// 0 / x; 0 * x; x & 0
-/// ```
 declare_clippy_lint! {
+    /// **What it does:** Checks for erasing operations, e.g., `x * 0`.
+    ///
+    /// **Why is this bad?** The whole expression can be replaced by zero.
+    /// This is most likely not the intended outcome and should probably be
+    /// corrected
+    ///
+    /// **Known problems:** None.
+    ///
+    /// **Example:**
+    /// ```rust
+    /// let x = 1;
+    /// 0 / x;
+    /// 0 * x;
+    /// x & 0;
+    /// ```
     pub ERASING_OP,
     correctness,
-    "using erasing operations, e.g. `x * 0` or `y & 0`"
+    "using erasing operations, e.g., `x * 0` or `y & 0`"
 }
 
 #[derive(Copy, Clone)]
@@ -29,6 +34,10 @@ impl LintPass for ErasingOp {
     fn get_lints(&self) -> LintArray {
         lint_array!(ERASING_OP)
     }
+
+    fn name(&self) -> &'static str {
+        "ErasingOp"
+    }
 }
 
 impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ErasingOp {
@@ -36,20 +45,20 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
         if in_macro(e.span) {
             return;
         }
-        if let ExprBinary(ref cmp, ref left, ref right) = e.node {
+        if let ExprKind::Binary(ref cmp, ref left, ref right) = e.node {
             match cmp.node {
-                BiMul | BiBitAnd => {
+                BinOpKind::Mul | BinOpKind::BitAnd => {
                     check(cx, left, e.span);
                     check(cx, right, e.span);
                 },
-                BiDiv => check(cx, left, e.span),
+                BinOpKind::Div => check(cx, left, e.span),
                 _ => (),
             }
         }
     }
 }
 
-fn check(cx: &LateContext, e: &Expr, span: Span) {
+fn check(cx: &LateContext<'_, '_>, e: &Expr, span: Span) {
     if let Some(Constant::Int(v)) = constant_simple(cx, cx.tables, e) {
         if v == 0 {
             span_lint(