Skip to content

Commit 75e20ba

Browse files
committed
Auto merge of rust-lang#7063 - daxpedda:debug-assert-panic, r=Manishearth
Fix false-positive `debug_assert` in `panic` This fixes a false-positive in `clippy::panic` when `debug_assert` is used with a message. Fixes rust-lang/rust-clippy#7062. changelog: Fix false-positive in `panic` when `debug_assert` is used with a message
2 parents fd5cf4e + cb14e7e commit 75e20ba

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

clippy_lints/src/panic_unimplemented.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ declare_lint_pass!(PanicUnimplemented => [UNIMPLEMENTED, UNREACHABLE, TODO, PANI
7474

7575
impl<'tcx> LateLintPass<'tcx> for PanicUnimplemented {
7676
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
77-
if match_panic_call(cx, expr).is_some() {
77+
if match_panic_call(cx, expr).is_some() && is_expn_of(expr.span, "debug_assert").is_none() {
7878
let span = get_outer_span(expr);
7979
if is_expn_of(expr.span, "unimplemented").is_some() {
8080
span_lint(

tests/ui/panicking_macros.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![warn(clippy::unimplemented, clippy::unreachable, clippy::todo, clippy::panic)]
2-
#![allow(clippy::assertions_on_constants)]
2+
#![allow(clippy::assertions_on_constants, clippy::eq_op)]
33

44
extern crate core;
55

@@ -43,6 +43,18 @@ fn core_versions() {
4343
unreachable!();
4444
}
4545

46+
fn debug_assert() {
47+
debug_assert!(true);
48+
debug_assert_eq!(true, true);
49+
debug_assert_ne!(true, false);
50+
}
51+
52+
fn debug_assert_msg() {
53+
debug_assert!(true, "test");
54+
debug_assert_eq!(true, true, "test");
55+
debug_assert_ne!(true, false, "test");
56+
}
57+
4658
fn main() {
4759
panic();
4860
todo();

0 commit comments

Comments
 (0)