Open
Description
Summary
.ok().expect("...")
doesnt trigger the expect_used
lint.
If one does { x.ok() }.expect("...");
The lint does trigger.
Lint Name
expect_used
Reproducer
I tried this code:
#![deny(clippy::expect_used)]
fn main() {
let x: Result<u8, u8> = Ok(0);
x.ok().expect("Huh");
}
I expected to see this happen:
error: used `expect()` on an `Option` value
--> src/main.rs:5:5
|
5 | x.ok().expect("Huh");
| ^^^^^^^^^^^^^^^^^
|
= note: if this value is `None`, it will panic
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#expect_used
Instead, this happened:
warning: called `ok().expect()` on a `Result` value
--> src/main.rs:5:5
|
5 | x.ok().expect("Huh");
| ^^^^^^^^^^^^^^^^^^^^
|
= help: you can call `expect()` directly on the `Result`
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ok_expect
= note: `#[warn(clippy::ok_expect)]` on by default
Version
rustc 1.90.0-nightly (e43d139a8 2025-07-09)
binary: rustc
commit-hash: e43d139a82620a268d3828a73e12a8679339e8f8
commit-date: 2025-07-09
host: x86_64-unknown-linux-gnu
release: 1.90.0-nightly
LLVM version: 20.1.7