This commit is contained in:
Caio 2024-09-11 13:58:05 -03:00
parent 78bdd4508d
commit 0905a7786e
2 changed files with 16 additions and 5 deletions

View File

@ -1,8 +1,8 @@
use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::macros::root_macro_call_first_node; use clippy_utils::macros::root_macro_call_first_node;
use clippy_utils::return_ty;
use clippy_utils::ty::is_type_diagnostic_item; use clippy_utils::ty::is_type_diagnostic_item;
use clippy_utils::visitors::{for_each_expr, Descend}; use clippy_utils::visitors::{for_each_expr, Descend};
use clippy_utils::{is_inside_always_const_context, return_ty};
use core::ops::ControlFlow; use core::ops::ControlFlow;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::intravisit::FnKind; use rustc_hir::intravisit::FnKind;
@ -68,10 +68,12 @@ fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, body: &'tcx hir
let Some(macro_call) = root_macro_call_first_node(cx, e) else { let Some(macro_call) = root_macro_call_first_node(cx, e) else {
return ControlFlow::Continue(Descend::Yes); return ControlFlow::Continue(Descend::Yes);
}; };
if matches!( if !is_inside_always_const_context(cx.tcx, e.hir_id)
&& matches!(
cx.tcx.item_name(macro_call.def_id).as_str(), cx.tcx.item_name(macro_call.def_id).as_str(),
"panic" | "assert" | "assert_eq" | "assert_ne" "panic" | "assert" | "assert_eq" | "assert_ne"
) { )
{
panics.push(macro_call.span); panics.push(macro_call.span);
ControlFlow::Continue(Descend::No) ControlFlow::Continue(Descend::No)
} else { } else {

View File

@ -71,6 +71,15 @@ fn function_result_with_custom_todo() -> Result<bool, String> // should not emit
Ok(true) Ok(true)
} }
fn issue_13381<const N: usize>() -> Result<(), String> {
const {
if N == 0 {
panic!();
}
}
Ok(())
}
fn main() -> Result<(), String> { fn main() -> Result<(), String> {
todo!("finish main method"); todo!("finish main method");
Ok(()) Ok(())