RS.CLIPPY.PANIC_IN_RESULT_FN
Functions of type `Result<..>` that contain `panic!()` or assertion
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: panic_in_result_fn. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for usage of panic! or assertions in a function whose return type is Result.
Why restrict this?
For some codebases, it is desirable for functions of type result to return an error instead of crashing. Hence panicking macros should be avoided.
Known problems
Functions called from a function returning a Result may invoke a panicking macro. This is not checked.
Example
fn result_with_panic() -> Result<bool, String>
{
panic!("error");
}
Use instead:
fn result_without_panic() -> Result<bool, String> {
Err(String::from("error"))
}