You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
Activity
github-actions commentedon Jun 30, 2026
A workspace is ready for this issue.
Powered by Worktree · Install
chore(lint): enable clippy::panic_in_result_fn (#96)