|
1 | 1 | use clippy_utils::diagnostics::span_lint;
|
| 2 | +use clippy_utils::is_in_test; |
2 | 3 | use clippy_utils::macros::{is_panic, root_macro_call_first_node};
|
3 | 4 | use rustc_hir::Expr;
|
4 | 5 | use rustc_lint::{LateContext, LateLintPass};
|
5 |
| -use rustc_session::declare_lint_pass; |
| 6 | +use rustc_session::impl_lint_pass; |
| 7 | + |
| 8 | +#[derive(Clone)] |
| 9 | +pub struct PanicUnimplemented { |
| 10 | + pub allow_panic_in_tests: bool, |
| 11 | +} |
6 | 12 |
|
7 | 13 | declare_clippy_lint! {
|
8 | 14 | /// ### What it does
|
@@ -77,15 +83,17 @@ declare_clippy_lint! {
|
77 | 83 | "usage of the `unreachable!` macro"
|
78 | 84 | }
|
79 | 85 |
|
80 |
| -declare_lint_pass!(PanicUnimplemented => [UNIMPLEMENTED, UNREACHABLE, TODO, PANIC]); |
| 86 | +impl_lint_pass!(PanicUnimplemented => [UNIMPLEMENTED, UNREACHABLE, TODO, PANIC]); |
81 | 87 |
|
82 | 88 | impl<'tcx> LateLintPass<'tcx> for PanicUnimplemented {
|
83 | 89 | fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
|
84 | 90 | let Some(macro_call) = root_macro_call_first_node(cx, expr) else {
|
85 | 91 | return;
|
86 | 92 | };
|
87 | 93 | if is_panic(cx, macro_call.def_id) {
|
88 |
| - if cx.tcx.hir().is_inside_const_context(expr.hir_id) { |
| 94 | + if cx.tcx.hir().is_inside_const_context(expr.hir_id) |
| 95 | + || self.allow_panic_in_tests && is_in_test(cx.tcx, expr.hir_id) |
| 96 | + { |
89 | 97 | return;
|
90 | 98 | }
|
91 | 99 |
|
|
0 commit comments