Skip to content

manual_ok_err automatic fix doesn't add {} when after else #14239

@Sliman4

Description

@Sliman4

Summary

Broken code after applying automatic fix

Reproducer

I tried this code:

fn main() {
    let n = if false {
        None
    } else if let Ok(n) = "1".parse::<u8>() {
        Some(n)
    } else {
        None
    };
}

with --fix

I expected to see this happen:

fn main() {
    let n = if false {
        None
    } else {
        "1".parse::<u8>().ok()
    };
}

Instead, this happened:

fn main() {
    let n = if false {
        None
    } else "1".parse::<u8>().ok();
}

Version

rustc 1.86.0-nightly (9cd60bd2c 2025-02-15)
binary: rustc
commit-hash: 9cd60bd2ccc41bc898d2ad86728f14035d2df72d
commit-date: 2025-02-15
host: x86_64-unknown-linux-gnu
release: 1.86.0-nightly
LLVM version: 19.1.7

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions