diff options
| author | bors <bors@rust-lang.org> | 2024-09-17 12:34:00 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-09-17 12:34:00 +0000 |
| commit | 903293b19936422e2d17a7a92e460e7874630443 (patch) | |
| tree | d7dd62e80e7df0dc794651eb54377a80c7fe0e49 | |
| parent | 25367459176bf0fd385594611d5a7c76fbcfa883 (diff) | |
| parent | 0905a7786e44727b265cb11486d742f1c6681e7d (diff) | |
| download | rust-903293b19936422e2d17a7a92e460e7874630443.tar.gz rust-903293b19936422e2d17a7a92e460e7874630443.zip | |
Auto merge of #13382 - c410-f3r:blah, r=y21
[`missing_panics_doc`] Fix #13381 Fix #13381 Makes `missing_panics_doc` act like other "panicking" lints (`unwrap_used`, `panic`, etc) in constant environments. changelog: Ignore `missing_panics_doc` in constant environments
| -rw-r--r-- | clippy_lints/src/panic_in_result_fn.rs | 12 | ||||
| -rw-r--r-- | tests/ui/panic_in_result_fn.rs | 9 |
2 files changed, 16 insertions, 5 deletions
diff --git a/clippy_lints/src/panic_in_result_fn.rs b/clippy_lints/src/panic_in_result_fn.rs index 381975199d2..fa15d5e4f9f 100644 --- a/clippy_lints/src/panic_in_result_fn.rs +++ b/clippy_lints/src/panic_in_result_fn.rs @@ -1,8 +1,8 @@ use clippy_utils::diagnostics::span_lint_and_then; 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::visitors::{for_each_expr, Descend}; +use clippy_utils::{is_inside_always_const_context, return_ty}; use core::ops::ControlFlow; use rustc_hir as hir; 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 { return ControlFlow::Continue(Descend::Yes); }; - if matches!( - cx.tcx.item_name(macro_call.def_id).as_str(), - "panic" | "assert" | "assert_eq" | "assert_ne" - ) { + if !is_inside_always_const_context(cx.tcx, e.hir_id) + && matches!( + cx.tcx.item_name(macro_call.def_id).as_str(), + "panic" | "assert" | "assert_eq" | "assert_ne" + ) + { panics.push(macro_call.span); ControlFlow::Continue(Descend::No) } else { diff --git a/tests/ui/panic_in_result_fn.rs b/tests/ui/panic_in_result_fn.rs index aaaf9a109ac..e2375aa996f 100644 --- a/tests/ui/panic_in_result_fn.rs +++ b/tests/ui/panic_in_result_fn.rs @@ -71,6 +71,15 @@ fn function_result_with_custom_todo() -> Result<bool, String> // should not emit Ok(true) } +fn issue_13381<const N: usize>() -> Result<(), String> { + const { + if N == 0 { + panic!(); + } + } + Ok(()) +} + fn main() -> Result<(), String> { todo!("finish main method"); Ok(()) |
