Skip to content

Allow irrefutable patterns in if-let statements #2081

@Nokel81

Description

@Nokel81

This might seem a bit strange but not allowing them has brought up some strange results for me.

The equivalent can be done with a plain match statement which is defiantly not as clean. In the docs it says to just use a plane let statement, but that is not always possible because of macros. If you accept a pattern in a macro then the ability to have the following -

if let $p = $val {
    $b
}

instead of

#[allow(unreachable_patterns)]
match $val {
    $p => {
        $b;
        break;
    },
    _ => ()
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-langRelevant to the language team, which will review and decide on the RFC.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions