Skip to content

Commit c6dd7a0

Browse files
committed
Fix #13381
1 parent 78bdd45 commit c6dd7a0

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

clippy_lints/src/panic_in_result_fn.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,12 @@ fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, body: &'tcx hir
6868
let Some(macro_call) = root_macro_call_first_node(cx, e) else {
6969
return ControlFlow::Continue(Descend::Yes);
7070
};
71-
if matches!(
72-
cx.tcx.item_name(macro_call.def_id).as_str(),
73-
"panic" | "assert" | "assert_eq" | "assert_ne"
74-
) {
71+
if !cx.tcx.hir().is_inside_always_const_context(e.hir_id)
72+
&& matches!(
73+
cx.tcx.item_name(macro_call.def_id).as_str(),
74+
"panic" | "assert" | "assert_eq" | "assert_ne"
75+
)
76+
{
7577
panics.push(macro_call.span);
7678
ControlFlow::Continue(Descend::No)
7779
} else {

tests/ui/panic_in_result_fn.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,15 @@ fn function_result_with_custom_todo() -> Result<bool, String> // should not emit
7171
Ok(true)
7272
}
7373

74+
fn issue_13381<const N: usize>() -> Result<(), String> {
75+
const {
76+
if N == 0 {
77+
panic!();
78+
}
79+
}
80+
Ok(())
81+
}
82+
7483
fn main() -> Result<(), String> {
7584
todo!("finish main method");
7685
Ok(())

0 commit comments

Comments
 (0)