about summary refs log tree commit diff
diff options
context:
space:
mode:
authoriobtl <tedmundhtl@gmail.com>2021-07-06 15:14:53 +0800
committeriobtl <tedmundhtl@gmail.com>2021-07-06 15:14:53 +0800
commiteeefbb7617c85cb1b51a4758f3d4743f01966578 (patch)
tree2a1200465f1f0545097998ef749ef1c873ec47e3
parent64d74df19c582a10ad41ddce496528e597b06765 (diff)
downloadrust-eeefbb7617c85cb1b51a4758f3d4743f01966578.tar.gz
rust-eeefbb7617c85cb1b51a4758f3d4743f01966578.zip
fix false positive (panic message) with assert macro using message parameter
-rw-r--r--clippy_lints/src/panic_unimplemented.rs4
-rw-r--r--tests/ui/panicking_macros.rs16
2 files changed, 19 insertions, 1 deletions
diff --git a/clippy_lints/src/panic_unimplemented.rs b/clippy_lints/src/panic_unimplemented.rs
index 1a680e7607e..dc28874c16e 100644
--- a/clippy_lints/src/panic_unimplemented.rs
+++ b/clippy_lints/src/panic_unimplemented.rs
@@ -74,7 +74,9 @@ 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() && is_expn_of(expr.span, "debug_assert").is_none() {
+        if match_panic_call(cx, expr).is_some()
+            && (is_expn_of(expr.span, "debug_assert").is_none() && is_expn_of(expr.span, "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 93b236f7473..73380646462 100644
--- a/tests/ui/panicking_macros.rs
+++ b/tests/ui/panicking_macros.rs
@@ -43,6 +43,18 @@ fn core_versions() {
     unreachable!();
 }
 
+fn assert() {
+    assert!(true);
+    assert_eq!(true, true);
+    assert_ne!(true, false);
+}
+
+fn assert_msg() {
+    assert!(true, "this should not panic");
+    assert_eq!(true, true, "this should not panic");
+    assert_ne!(true, false, "this should not panic");
+}
+
 fn debug_assert() {
     debug_assert!(true);
     debug_assert_eq!(true, true);
@@ -61,4 +73,8 @@ fn main() {
     unimplemented();
     unreachable();
     core_versions();
+    assert();
+    assert_msg();
+    debug_assert();
+    debug_assert_msg();
 }