about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--clippy_lints/src/erasing_op.rs16
-rw-r--r--clippy_lints/src/get_last_with_len.rs3
-rw-r--r--clippy_lints/src/neg_multiply.rs31
-rw-r--r--clippy_lints/src/transmuting_null.rs21
4 files changed, 23 insertions, 48 deletions
diff --git a/clippy_lints/src/erasing_op.rs b/clippy_lints/src/erasing_op.rs
index 5fa52d8030c..267f1a27904 100644
--- a/clippy_lints/src/erasing_op.rs
+++ b/clippy_lints/src/erasing_op.rs
@@ -48,14 +48,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ErasingOp {
 }
 
 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(
-                cx,
-                ERASING_OP,
-                span,
-                "this operation will always return zero. This is likely not the intended outcome",
-            );
-        }
+    if let Some(Constant::Int(0)) = constant_simple(cx, cx.tables, e) {
+        span_lint(
+            cx,
+            ERASING_OP,
+            span,
+            "this operation will always return zero. This is likely not the intended outcome",
+        );
     }
 }
diff --git a/clippy_lints/src/get_last_with_len.rs b/clippy_lints/src/get_last_with_len.rs
index 9910fa8820a..a43bc3ec1aa 100644
--- a/clippy_lints/src/get_last_with_len.rs
+++ b/clippy_lints/src/get_last_with_len.rs
@@ -79,8 +79,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for GetLastWithLen {
 
             // RHS of subtraction is 1
             if let ExprKind::Lit(rhs_lit) = &rhs.kind;
-            if let LitKind::Int(rhs_value, ..) = rhs_lit.node;
-            if rhs_value == 1;
+            if let LitKind::Int(1, ..) = rhs_lit.node;
 
             then {
                 let mut applicability = Applicability::MachineApplicable;
diff --git a/clippy_lints/src/neg_multiply.rs b/clippy_lints/src/neg_multiply.rs
index b4901cd3ffd..aec0664a29b 100644
--- a/clippy_lints/src/neg_multiply.rs
+++ b/clippy_lints/src/neg_multiply.rs
@@ -2,7 +2,7 @@ use if_chain::if_chain;
 use rustc::hir::*;
 use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
 use rustc::{declare_lint_pass, declare_tool_lint};
-use syntax::source_map::{Span, Spanned};
+use syntax::source_map::Span;
 
 use crate::consts::{self, Constant};
 use crate::utils::span_lint;
@@ -28,19 +28,14 @@ declare_lint_pass!(NegMultiply => [NEG_MULTIPLY]);
 #[allow(clippy::match_same_arms)]
 impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NegMultiply {
     fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
-        if let ExprKind::Binary(
-            Spanned {
-                node: BinOpKind::Mul, ..
-            },
-            ref l,
-            ref r,
-        ) = e.kind
-        {
-            match (&l.kind, &r.kind) {
-                (&ExprKind::Unary(..), &ExprKind::Unary(..)) => (),
-                (&ExprKind::Unary(UnNeg, ref lit), _) => check_mul(cx, e.span, lit, r),
-                (_, &ExprKind::Unary(UnNeg, ref lit)) => check_mul(cx, e.span, lit, l),
-                _ => (),
+        if let ExprKind::Binary(ref op, ref left, ref right) = e.kind {
+            if BinOpKind::Mul == op.node {
+                match (&left.kind, &right.kind) {
+                    (&ExprKind::Unary(..), &ExprKind::Unary(..)) => {},
+                    (&ExprKind::Unary(UnNeg, ref lit), _) => check_mul(cx, e.span, lit, right),
+                    (_, &ExprKind::Unary(UnNeg, ref lit)) => check_mul(cx, e.span, lit, left),
+                    _ => {},
+                }
             }
         }
     }
@@ -49,14 +44,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NegMultiply {
 fn check_mul(cx: &LateContext<'_, '_>, span: Span, lit: &Expr, exp: &Expr) {
     if_chain! {
         if let ExprKind::Lit(ref l) = lit.kind;
-        if let Constant::Int(val) = consts::lit_to_constant(&l.node, cx.tables.expr_ty(lit));
-        if val == 1;
+        if let Constant::Int(1) = consts::lit_to_constant(&l.node, cx.tables.expr_ty(lit));
         if cx.tables.expr_ty(exp).is_integral();
         then {
-            span_lint(cx,
-                      NEG_MULTIPLY,
-                      span,
-                      "Negation by multiplying with -1");
+            span_lint(cx, NEG_MULTIPLY, span, "Negation by multiplying with -1");
         }
     }
 }
diff --git a/clippy_lints/src/transmuting_null.rs b/clippy_lints/src/transmuting_null.rs
index ed0be2f669a..9d1d783f60c 100644
--- a/clippy_lints/src/transmuting_null.rs
+++ b/clippy_lints/src/transmuting_null.rs
@@ -48,14 +48,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TransmutingNull {
                     if let ExprKind::Path(ref _qpath) = args[0].kind;
                     let x = const_eval_context.expr(&args[0]);
                     if let Some(constant) = x;
-                    if let Constant::RawPtr(ptr_value) = constant;
-                    if ptr_value == 0;
+                    if let Constant::RawPtr(0) = constant;
                     then {
-                        span_lint(
-                            cx,
-                            TRANSMUTING_NULL,
-                            expr.span,
-                            LINT_MSG)
+                        span_lint(cx, TRANSMUTING_NULL, expr.span, LINT_MSG)
                     }
                 }
 
@@ -66,11 +61,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TransmutingNull {
                     if let ExprKind::Lit(ref lit) = inner_expr.kind;
                     if let LitKind::Int(0, _) = lit.node;
                     then {
-                        span_lint(
-                            cx,
-                            TRANSMUTING_NULL,
-                            expr.span,
-                            LINT_MSG)
+                        span_lint(cx, TRANSMUTING_NULL, expr.span, LINT_MSG)
                     }
                 }
 
@@ -82,11 +73,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TransmutingNull {
                     if match_qpath(path1, &paths::STD_PTR_NULL);
                     if args1.len() == 0;
                     then {
-                        span_lint(
-                            cx,
-                            TRANSMUTING_NULL,
-                            expr.span,
-                            LINT_MSG)
+                        span_lint(cx, TRANSMUTING_NULL, expr.span, LINT_MSG)
                     }
                 }