RS.CLIPPY.ERR_EXPECT

R#"using `.err().expect("")` when `.expect_err("")` can be used"#

This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: err_expect. Copyright ©2025 The Rust Team. All rights reserved.

What it does

Checks for .err().expect() calls on the Result type.

Why is this bad?

.expect_err() can be called directly to avoid the extra type conversion from err().

Example

let x: Result<u32, &str> = Ok(10);
x.err().expect("Testing err().expect()");

Use instead:

let x: Result<u32, &str> = Ok(10);
x.expect_err("Testing expect_err");

Configuration

  • msrv: The minimum rust version that the project supports. Defaults to the rust-version field in Cargo.toml

    (default: current version)