Skip to content

? operator for propagating Reslut, Option - does clippy give false positive warning ? #14675

Closed
@tomaszdrozdz

Description

@tomaszdrozdz

Description

Hello all,

Is this warning OK - or false positive ?

let r: Result<i32, std::num::ParseIntError> = (|| -> Result<i32, std::num::ParseIntError> { 
    Ok("1".parse::<i32>()?) })();

Gives:

question mark operator is useless here
for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_question_mark
#[warn(clippy::needless_question_mark)] on by default


But of course:

let r: Result<i32, std::num::ParseIntError> = (|| -> Result<i32, std::num::ParseIntError> { 
    Ok("1".parse::<i32>() ) })();

Gives:

mismatched types
expected type i32
found enum std::result::Result<i32, std::num::ParseIntError>


And this:

let r: Result<i32, std::num::ParseIntError> = (|| -> Result<i32, std::num::ParseIntError> { 
    Ok("1".parse::<i32>()? + "2".parse::<i32>()?) })();

does not produce warning.

Version


Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions