Skip to content

Commit eeefbb7

Browse files
committed
fix false positive (panic message) with assert macro using message parameter
1 parent 64d74df commit eeefbb7

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

clippy_lints/src/panic_unimplemented.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ 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() && is_expn_of(expr.span, "debug_assert").is_none() {
77+
if match_panic_call(cx, expr).is_some()
78+
&& (is_expn_of(expr.span, "debug_assert").is_none() && is_expn_of(expr.span, "assert").is_none())
79+
{
7880
let span = get_outer_span(expr);
7981
if is_expn_of(expr.span, "unimplemented").is_some() {
8082
span_lint(

tests/ui/panicking_macros.rs

+16
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,18 @@ fn core_versions() {
4343
unreachable!();
4444
}
4545

46+
fn assert() {
47+
assert!(true);
48+
assert_eq!(true, true);
49+
assert_ne!(true, false);
50+
}
51+
52+
fn assert_msg() {
53+
assert!(true, "this should not panic");
54+
assert_eq!(true, true, "this should not panic");
55+
assert_ne!(true, false, "this should not panic");
56+
}
57+
4658
fn debug_assert() {
4759
debug_assert!(true);
4860
debug_assert_eq!(true, true);
@@ -61,4 +73,8 @@ fn main() {
6173
unimplemented();
6274
unreachable();
6375
core_versions();
76+
assert();
77+
assert_msg();
78+
debug_assert();
79+
debug_assert_msg();
6480
}

0 commit comments

Comments
 (0)