Skip to content

Enable clippy::panic_in_result_fn lint #95

Description

@tupe12334

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions