Clippy · Correctness
Panic or assertion inside a Result-returning function
clippy::panic_in_result_fn
A function that already returns Result should report the failure as Err instead of panicking.
- Category
- Correctness
- Default level
- warn
- Tier
- P2
- Producer
- Clippy
- Diff scope
- line
Not a defect when
The panic or assert checks an internal invariant rather than a recoverable input, such as an assert on a computed index, where returning Err would misreport a bug as a runtime failure.
What it reads
Clippy, with the compiler behind it. The only pass that compiles.
Tier
Ordinary defect.
The tier bounds how severe a rule may be; its category bounds the tier.Diff scope
The changed line itself.
What--scope contextual looks at to decide whether a change caused the finding.Change it
Turn it off, or make it blocking, without touching the code it flags:
rust-doctor --rule clippy::panic_in_result_fn=off .
rust-doctor --rule clippy::panic_in_result_fn=error .