Skip to content

Commit

Permalink
Auto merge of #7063 - daxpedda:debug-assert-panic, r=Manishearth
Browse files Browse the repository at this point in the history
Fix false-positive `debug_assert` in `panic`

This fixes a false-positive in `clippy::panic` when `debug_assert` is used with a message.

Fixes #7062.

changelog: Fix false-positive in `panic` when `debug_assert` is used with a message
  • Loading branch information
bors committed Apr 10, 2021
2 parents fd5cf4e + cb14e7e commit 75e20ba
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion clippy_lints/src/panic_unimplemented.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
14 changes: 13 additions & 1 deletion tests/ui/panicking_macros.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 75e20ba

Please sign in to comment.