about summary refs log tree commit diff
diff options
context:
space:
mode:
authorflip1995 <hello@philkrones.com>2019-04-18 11:47:39 +0200
committerflip1995 <hello@philkrones.com>2019-04-18 11:47:39 +0200
commitbe98df5ac3ef645a7d0743306dc11a4da61fc071 (patch)
tree5ac921355ae0a7f925eb8e0d6712f74265e2d2ec
parentb834dbb2d5924c947c3cbe47c863ea5b7470e567 (diff)
downloadrust-be98df5ac3ef645a7d0743306dc11a4da61fc071.tar.gz
rust-be98df5ac3ef645a7d0743306dc11a4da61fc071.zip
Don't lint debug_assert!(false)
-rw-r--r--clippy_lints/src/assertions_on_constants.rs11
1 files changed, 8 insertions, 3 deletions
diff --git a/clippy_lints/src/assertions_on_constants.rs b/clippy_lints/src/assertions_on_constants.rs
index ceea913233e..d342e0cd02a 100644
--- a/clippy_lints/src/assertions_on_constants.rs
+++ b/clippy_lints/src/assertions_on_constants.rs
@@ -33,10 +33,15 @@ declare_lint_pass!(AssertionsOnConstants => [ASSERTIONS_ON_CONSTANTS]);
 
 impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants {
     fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
+        let mut is_debug_assert = false;
         if_chain! {
             if let Some(assert_span) = is_direct_expn_of(e.span, "assert");
             if !in_macro(assert_span)
-                || is_direct_expn_of(assert_span, "debug_assert").map_or(false, |span| !in_macro(span));
+                || is_direct_expn_of(assert_span, "debug_assert").map_or(false, |span| {
+                    is_debug_assert = true;
+                    // Check that `debug_assert!` itself is not inside a macro
+                    !in_macro(span)
+                });
             if let ExprKind::Unary(_, ref lit) = e.node;
             then {
                 if let ExprKind::Lit(ref inner) = lit.node {
@@ -46,7 +51,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants {
                                 "assert!(true) will be optimized out by the compiler",
                                 "remove it");
                         },
-                        LitKind::Bool(false) => {
+                        LitKind::Bool(false) if !is_debug_assert => {
                             span_help_and_lint(
                                 cx, ASSERTIONS_ON_CONSTANTS, e.span,
                                 "assert!(false) should probably be replaced",
@@ -61,7 +66,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants {
                                 "assert!(const: true) will be optimized out by the compiler",
                                 "remove it");
                         },
-                        Constant::Bool(false) => {
+                        Constant::Bool(false) if !is_debug_assert => {
                             span_help_and_lint(cx, ASSERTIONS_ON_CONSTANTS, e.span,
                                 "assert!(const: false) should probably be replaced",
                                 "use panic!() or unreachable!()");