rust-lang / rust-lang/rust-clippy

Since 1.97.0, `clippy::question_mark` fires on code matching on `&Option`

Open
#17,386 2 comments 0 reactions 1 assignee View on GitHub

@profetia is already working on this.

Since Jul 16, 2026.

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

Description

Summary

Since 1.97.0 Clippy fires clippy::question_mark on code that handles &Option, while it shouldn't.

Lint Name

question_mark

Reproducer

I tried this code:

fn foo() -> &'static Option<i32> {
    &None
}

fn bar() -> Option<()> {
    match foo() {
        Some(it) => {
            dbg!(it);
        }
        None => return None,
    }
    Some(())
}

I saw this happen:

warning: this `match` expression can be replaced with `?`
  --> src/lib.rs:6:5
   |
 6 | /     match foo() {
 7 | |         Some(it) => {
 8 | |             dbg!(it);
...  |
11 | |     }
   | |_____^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.97.0/index.html#question_mark
   = note: `#[warn(clippy::question_mark)]` on by default
help: try instead
   |
 6 ~     {
 7 +         let it = foo()?;
 8 +         dbg!(it);
 9 +     }
   |

I expected to see this happen:

The lint should not fire. The suggested fix does not compile, you cannot use ? on &Option.

Version

Additional Labels

No response

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.