RS.CLIPPY.NEEDLESS_QUESTION_MARK

Using `Ok(x?)` or `Some(x?)` where `x` would be equivalent

This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: needless_question_mark. Copyright ©2025 The Rust Team. All rights reserved.

What it does

Suggests replacing Ok(x?) or Some(x?) with x in return positions where the ? operator is not needed to convert the type of x.

Why is this bad?

There's no reason to use ? to short-circuit when execution of the body will end there anyway.

Example

fn f(s: &str) -> Option<usize> {
    Some(s.find(\'x\')?)
}

fn g(s: &str) -> Result<usize, ParseIntError> {
    Ok(s.parse()?)
}

Use instead:

fn f(s: &str) -> Option<usize> {
    s.find(\'x\')
}

fn g(s: &str) -> Result<usize, ParseIntError> {
    s.parse()
}