rust-lang / rust-lang/rust-clippy
Since 1.97.0, `clippy::question_mark` fires on code matching on `&Option`
Open
@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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.