Skip to content

clippy::question_mark suggests code that is semantically different to the original #7924

Open
@louismrose

Description

@louismrose

Lint name:
clippy::question_mark

I tried this code:

fn multiply(
    first_number_str: &str,
    second_number_str: &str,
) -> std::result::Result<i32, ParseIntError> {
    let first_number = first_number_str.parse::<i32>()?;
    let second_number = second_number_str.parse::<i32>()?;

    Ok(first_number * second_number)
}

if multiply("4", "5").is_err() {
  return Ok(());
}

I expected to see this happen: no recommendation

Instead, this happened:

65 | /             if multiply("4", "5").is_err() {
66 | |                 return Ok(());
67 | |             }
   | |_____________^ help: replace it with: `multiply("4", "5")?;`

The suggested replacement is not semantically equivalent to the original.

Meta

Rust version (rustc -Vv):

rustc 1.58.0-nightly (18bc4bee9 2021-11-02)
binary: rustc
commit-hash: 18bc4bee9710b181b440a472635150f0d6257713
commit-date: 2021-11-02
host: x86_64-apple-darwin
release: 1.58.0-nightly
LLVM version: 13.0.0

Metadata

Metadata

Assignees

No one assigned

    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