]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/erasing_op.rs
Auto merge of #81993 - flip1995:clippyup, r=Manishearth
[rust.git] / clippy_lints / src / erasing_op.rs
index 3ac2f90ce01b4cd77f06bbffa95a35525c769d68..dbd1ff514f0e13292b6d7a8a0aa2efc7b2e220d6 100644 (file)
@@ -1,10 +1,10 @@
-use rustc::hir::*;
-use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
-use rustc::{declare_lint_pass, declare_tool_lint};
-use syntax::source_map::Span;
+use rustc_hir::{BinOpKind, Expr, ExprKind};
+use rustc_lint::{LateContext, LateLintPass};
+use rustc_session::{declare_lint_pass, declare_tool_lint};
+use rustc_span::source_map::Span;
 
 use crate::consts::{constant_simple, Constant};
-use crate::utils::{in_macro_or_desugar, span_lint};
+use crate::utils::span_lint;
 
 declare_clippy_lint! {
     /// **What it does:** Checks for erasing operations, e.g., `x * 0`.
 
 declare_lint_pass!(ErasingOp => [ERASING_OP]);
 
-impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ErasingOp {
-    fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
-        if in_macro_or_desugar(e.span) {
+impl<'tcx> LateLintPass<'tcx> for ErasingOp {
+    fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) {
+        if e.span.from_expansion() {
             return;
         }
-        if let ExprKind::Binary(ref cmp, ref left, ref right) = e.node {
+        if let ExprKind::Binary(ref cmp, ref left, ref right) = e.kind {
             match cmp.node {
                 BinOpKind::Mul | BinOpKind::BitAnd => {
                     check(cx, left, e.span);
@@ -47,15 +47,13 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
     }
 }
 
-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",
-            );
-        }
+fn check(cx: &LateContext<'_>, e: &Expr<'_>, span: Span) {
+    if let Some(Constant::Int(0)) = constant_simple(cx, cx.typeck_results(), e) {
+        span_lint(
+            cx,
+            ERASING_OP,
+            span,
+            "this operation will always return zero. This is likely not the intended outcome",
+        );
     }
 }