about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGiorgio Gambino <gambnio.giorgio@gmail.com>2018-10-29 22:23:45 +0100
committerGiorgio Gambino <gambnio.giorgio@gmail.com>2018-10-29 22:23:45 +0100
commitc0c1f1f7fa1cd2d9d65d3b2cd4b3943c62106328 (patch)
tree669bd6aff43205b729dcbcef544b3a8f172cc947
parent62f16803e8abb176279d3160f0287ad0f0575105 (diff)
downloadrust-c0c1f1f7fa1cd2d9d65d3b2cd4b3943c62106328.tar.gz
rust-c0c1f1f7fa1cd2d9d65d3b2cd4b3943c62106328.zip
Fix #3335 rev2: bool_comparison triggers 3 times on same code
-rw-r--r--clippy_lints/src/needless_bool.rs101
1 files changed, 51 insertions, 50 deletions
diff --git a/clippy_lints/src/needless_bool.rs b/clippy_lints/src/needless_bool.rs
index 3afccf9f984..e13f757adb9 100644
--- a/clippy_lints/src/needless_bool.rs
+++ b/clippy_lints/src/needless_bool.rs
@@ -133,56 +133,57 @@ impl LintPass for BoolComparison {
 
 impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoolComparison {
     fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
-        if !in_macro(e.span) {
-            use self::Expression::*;
-            if let ExprKind::Binary(Spanned { node: BinOpKind::Eq, .. }, ref left_side, ref right_side) = e.node {
-                match (fetch_bool_expr(left_side), fetch_bool_expr(right_side)) {
-                    (Bool(true), Other) => {
-                        let hint = snippet(cx, right_side.span, "..").into_owned();
-                        span_lint_and_sugg(
-                            cx,
-                            BOOL_COMPARISON,
-                            e.span,
-                            "equality checks against true are unnecessary",
-                            "try simplifying it as shown",
-                            hint,
-                        );
-                    },
-                    (Other, Bool(true)) => {
-                        let hint = snippet(cx, left_side.span, "..").into_owned();
-                        span_lint_and_sugg(
-                            cx,
-                            BOOL_COMPARISON,
-                            e.span,
-                            "equality checks against true are unnecessary",
-                            "try simplifying it as shown",
-                            hint,
-                        );
-                    },
-                    (Bool(false), Other) => {
-                        let hint = Sugg::hir(cx, right_side, "..");
-                        span_lint_and_sugg(
-                            cx,
-                            BOOL_COMPARISON,
-                            e.span,
-                            "equality checks against false can be replaced by a negation",
-                            "try simplifying it as shown",
-                            (!hint).to_string(),
-                        );
-                    },
-                    (Other, Bool(false)) => {
-                        let hint = Sugg::hir(cx, left_side, "..");
-                        span_lint_and_sugg(
-                            cx,
-                            BOOL_COMPARISON,
-                            e.span,
-                            "equality checks against false can be replaced by a negation",
-                            "try simplifying it as shown",
-                            (!hint).to_string(),
-                        );
-                    },
-                    _ => (),
-                }
+        if in_macro(e.span) {
+            return;
+        }
+        use self::Expression::*;
+        if let ExprKind::Binary(Spanned { node: BinOpKind::Eq, .. }, ref left_side, ref right_side) = e.node {
+            match (fetch_bool_expr(left_side), fetch_bool_expr(right_side)) {
+                (Bool(true), Other) => {
+                    let hint = snippet(cx, right_side.span, "..").into_owned();
+                    span_lint_and_sugg(
+                        cx,
+                        BOOL_COMPARISON,
+                        e.span,
+                        "equality checks against true are unnecessary",
+                        "try simplifying it as shown",
+                        hint,
+                    );
+                },
+                (Other, Bool(true)) => {
+                    let hint = snippet(cx, left_side.span, "..").into_owned();
+                    span_lint_and_sugg(
+                        cx,
+                        BOOL_COMPARISON,
+                        e.span,
+                        "equality checks against true are unnecessary",
+                        "try simplifying it as shown",
+                        hint,
+                    );
+                },
+                (Bool(false), Other) => {
+                    let hint = Sugg::hir(cx, right_side, "..");
+                    span_lint_and_sugg(
+                        cx,
+                        BOOL_COMPARISON,
+                        e.span,
+                        "equality checks against false can be replaced by a negation",
+                        "try simplifying it as shown",
+                        (!hint).to_string(),
+                    );
+                },
+                (Other, Bool(false)) => {
+                    let hint = Sugg::hir(cx, left_side, "..");
+                    span_lint_and_sugg(
+                        cx,
+                        BOOL_COMPARISON,
+                        e.span,
+                        "equality checks against false can be replaced by a negation",
+                        "try simplifying it as shown",
+                        (!hint).to_string(),
+                    );
+                },
+                _ => (),
             }
         }
     }