Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tomaszdrozdz opened this issue Apr 23, 2025 · 2 comments · Fixed by #14682
Closed

Comments

@tomaszdrozdz
Copy link

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

@tomaszdrozdz tomaszdrozdz changed the title ? operator for propagating Reslut, Option - is clippy give false positive warning ? ? operator for propagating Reslut, Option - does clippy give false positive warning ? Apr 23, 2025
github-merge-queue bot pushed a commit that referenced this issue Apr 23, 2025
Fixes #14675 by making it
clearer that the constructor needs to be removed as well
Also fixes #8392

changelog: none
@Alexendoo
Copy link
Member

Tweaked the message to be clearer in #14682, the lint wants you to remove the Ok as well as the ?

@tomaszdrozdz
Copy link
Author

Thank You :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants