Skip to content

irrefutable_let_patterns should not lint at the start of an else if let-chain #128661

Closed
@Jarcho

Description

@Jarcho

The following triggers irrefutable_let_patterns:

fn expensive() -> u32 {
    0
}

fn option(x: u32) -> Option<u32> {
    Some(x)
}

fn f(x: bool) {
    if x {
        // something
    } else if let foo = expensive()
        && let Some(bar) = option(foo)
    {
        // use `foo` and `bar`
    } else {
        // something
    }
}

Though let foo = expensive() is irrefutable, it would add an extra layer of nesting to move it into a regular let statement. e.g.

if x {
    // something
} else {
    let foo = expensive()
    if let Some(bar) = option(foo) {
        // use `foo` and `bar`
    } else {
        // something
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.F-let_chains`#![feature(let_chains)]`L-irrefutable_let_patternsLint: irrefutable_let_patternsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions