Skip to content

Suggest rewriting applicable match or if-let statements to new let-else syntax #7540

Closed
@kangalio

Description

@kangalio

What it does

Once the new let-else syntax is introduced, it would be awesome to have a lint which detects match and if-let statements which could be improved with let-else.

Categories (optional)

  • Kind: clippy::style

What is the advantage of the recommended code over the original code

It's more concise and idiomatic.

Drawbacks

None.

Example

let foo = match expr1 {
    Some(foo) => foo,
    None => {
        // error handling code
        return;
    }
};

let bar = if let Some(bar) = expr2 {
    bar
} else {
    // error handling code
    return;
};

Could be written as:

let Some(foo) = expr1 else {
    // error handling code
    return;
};

let Some(bar) = expr2 else {
    // error handling code
    return;
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions