Skip to content

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

Description

@ChayimFriedman2

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

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions