What this lint catches
clippy::panic_in_result_fn flags any function that returns Result or Option yet contains a panic!, todo!, unimplemented!, or unreachable! call at its top level.
Why it matters
When a function's return type already signals fallibility through Result/Option, an internal panic! is a contract violation: callers expect to receive an Err (or None) on failure, not a process crash. Panicking inside these functions:
- Bypasses structured error propagation (the whole reason
Result exists)
- Cannot be caught or recovered from by callers
- Makes the function's failure modes invisible at the type level
The idiomatic fix is to replace panic!("msg") with return Err(anyhow!("msg")) (or an equivalent), keeping failure handling consistent and caller-visible.
Current state
The codebase has zero violations today — adding the lint as deny locks in this clean state and prevents any future regression from sneaking in.
Proposed change
Add to [lints.clippy] in Cargo.toml:
# Prevent panic!() inside Result/Option-returning functions; failures must be
# returned as Err(_)/None so callers can handle them rather than crashing.
panic_in_result_fn = "deny"
This issue was opened by the Clippy lint improvements → issue + PR (Rust repos) → Slack routine of moadim. CC @tupe12334
What this lint catches
clippy::panic_in_result_fnflags any function that returnsResultorOptionyet contains apanic!,todo!,unimplemented!, orunreachable!call at its top level.Why it matters
When a function's return type already signals fallibility through
Result/Option, an internalpanic!is a contract violation: callers expect to receive anErr(orNone) on failure, not a process crash. Panicking inside these functions:Resultexists)The idiomatic fix is to replace
panic!("msg")withreturn Err(anyhow!("msg"))(or an equivalent), keeping failure handling consistent and caller-visible.Current state
The codebase has zero violations today — adding the lint as
denylocks in this clean state and prevents any future regression from sneaking in.Proposed change
Add to
[lints.clippy]inCargo.toml:This issue was opened by the Clippy lint improvements → issue + PR (Rust repos) → Slack routine of moadim. CC @tupe12334