about summary refs log tree commit diff
diff options
context:
space:
mode:
authordaxpedda <daxpedda@gmail.com>2021-04-10 23:37:18 +0200
committerdaxpedda <daxpedda@gmail.com>2021-04-10 23:37:18 +0200
commitcb14e7ebf40bb6edf9307813b341a9119800ef49 (patch)
tree6ea9d3a1bf4735c8a2699bc6d351affc50141d69
parentfd5cf4e82d3422887585fd148369b592f95cd169 (diff)
downloadrust-cb14e7ebf40bb6edf9307813b341a9119800ef49.tar.gz
rust-cb14e7ebf40bb6edf9307813b341a9119800ef49.zip
Fix false-positive `debug_assert` in `panic`
-rw-r--r--clippy_lints/src/panic_unimplemented.rs2
-rw-r--r--tests/ui/panicking_macros.rs14
2 files changed, 14 insertions, 2 deletions
diff --git a/clippy_lints/src/panic_unimplemented.rs b/clippy_lints/src/panic_unimplemented.rs
index 1e946858947..1a680e7607e 100644
--- a/clippy_lints/src/panic_unimplemented.rs
+++ b/clippy_lints/src/panic_unimplemented.rs
@@ -74,7 +74,7 @@ declare_lint_pass!(PanicUnimplemented => [UNIMPLEMENTED, UNREACHABLE, TODO, PANI
 
 impl<'tcx> LateLintPass<'tcx> for PanicUnimplemented {
     fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
-        if match_panic_call(cx, expr).is_some() {
+        if match_panic_call(cx, expr).is_some() && is_expn_of(expr.span, "debug_assert").is_none() {
             let span = get_outer_span(expr);
             if is_expn_of(expr.span, "unimplemented").is_some() {
                 span_lint(
diff --git a/tests/ui/panicking_macros.rs b/tests/ui/panicking_macros.rs
index 77fcb8dfd02..93b236f7473 100644
--- a/tests/ui/panicking_macros.rs
+++ b/tests/ui/panicking_macros.rs
@@ -1,5 +1,5 @@
 #![warn(clippy::unimplemented, clippy::unreachable, clippy::todo, clippy::panic)]
-#![allow(clippy::assertions_on_constants)]
+#![allow(clippy::assertions_on_constants, clippy::eq_op)]
 
 extern crate core;
 
@@ -43,6 +43,18 @@ fn core_versions() {
     unreachable!();
 }
 
+fn debug_assert() {
+    debug_assert!(true);
+    debug_assert_eq!(true, true);
+    debug_assert_ne!(true, false);
+}
+
+fn debug_assert_msg() {
+    debug_assert!(true, "test");
+    debug_assert_eq!(true, true, "test");
+    debug_assert_ne!(true, false, "test");
+}
+
 fn main() {
     panic();
     todo();