Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kangalio opened this issue Aug 6, 2021 · 1 comment
Labels
A-lint Area: New lints

Comments

@kangalio
Copy link

kangalio commented Aug 6, 2021

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;
};
@kangalio kangalio added the A-lint Area: New lints label Aug 6, 2021
@kangalio
Copy link
Author

kangalio commented Nov 3, 2022

Implemented in #8437

@kangalio kangalio closed this as completed Nov 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
Development

No branches or pull requests

1 participant