rust-lang / rust-lang/rust-clippy

question_mark should trigger on Some-pattern-matching let else statement

Open
#17,545 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-enhancement I-false-negative
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

Summary

I think that clippy::question_mark should trigger for let Some(_) = _ else { return Err(_); }

Lint Name

manual_ok_or , question_mark

Reproducer

I tried this code:

let an_option: Option<i32> = None;
let Some(_something) = an_option else {
    return Err(1);
};

I expected to see this happen:

A warning being produced telling me to use Option::ok_or or Option::ok_or_else, replacing the snippet with this:

let an_option: Option<i32> = None;
let _something = an_option.ok_or(1)?;

Instead, this happened:

Nothing, the code made it into production :c

Version
rustc 1.99.0-nightly (771916f90 2026-08-08)
binary: rustc
commit-hash: 771916f9028e7fe56d2685f2c4f698de5d7d6a45
commit-date: 2026-08-08
host: x86_64-unknown-linux-gnu
release: 1.99.0-nightly
LLVM version: 23.1.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No source file or test is named. Start by reading the Rust Clippy implementations for question_mark and manual_ok_or, then locate the lint test suite; reproduce the Some-pattern let-else case and consider the issue resolved when the expected ok_or(...)? suggestion is covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.