Rules / TAU-P004

No panics inside fallible functions

decided by Clippy kernel deny core deny edge deny
Applies to tests: no Exceptions: #[expect] + reason

Why

A function that returns Result has promised to report failure as a value; panicking inside it breaks that promise.

Fix

Map the failure into the function's error type and return it with ?.

What it checks

Lints: clippy::unwrap_in_result, clippy::panic_in_result_fn

Seen in fixtures

rej-panic-in-result/src/lib.rs core

//! An assertion inside a fallible function. /// Why a value was refused.#[derive(Debug)]pub enum Refused {    /// It was zero.    Zero,} /// Checks a value.////// # Errors/// `Refused::Zero` for zero.pub fn check(x: u8) -> Result<u8, Refused> {    assert!(x < 200, "out of range");    if x == 0 { Err(Refused::Zero) } else { Ok(x) }}

$ cargo tauten check

error[TAU-P004]: used `panic!()` or assertion in a function that returns `Result`  --> rej-panic-in-result/src/lib.rs:14:1 (core crate `rej-panic-in-result`)  = rule: No panics inside fallible functions (decided by Clippy)  = fix: Map the failure into the function's error type and return it with `?`.
Fixture rej-panic-in-result (core) expects TAU-P004. Output captured at 0200db3.

In the terminal

cargo tauten explain TAU-P004

$ cargo tauten explain TAU-P004

TAU-P004: No panics inside fallible functions Why: A function that returns Result has promised to report failure as a value; panicking inside it breaks that promise. Fix: Map the failure into the function's error type and return it with `?`. Decided by: ClippyDecides: No panic or unwrap inside a function that returns `Result`.Sees: resolved; complete: yesDoes not see: Code expanded from macros defined in other crates (clippy skips it); code disabled by `cfg`; build scripts.Applies to tests: noExceptions allowed: with #[expect(.., reason)]  kernel deny  core deny  edge denyLints: clippy::unwrap_in_result, clippy::panic_in_result_fn