Skip to content

expect_used doesnt trigger for .ok().expect("...") #15247

Open
@vivax3794

Description

@vivax3794

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

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn't

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions