Skip to content
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

Suggest let...else with return over match with return #9749

Closed
frewsxcv opened this issue Oct 29, 2022 · 1 comment
Closed

Suggest let...else with return over match with return #9749

frewsxcv opened this issue Oct 29, 2022 · 1 comment
Labels
A-lint Area: New lints

Comments

@frewsxcv
Copy link
Member

frewsxcv commented Oct 29, 2022

What it does

Utilizes the new let...else syntax when the user returns in the non-unwrapping case

Lint Name

let-else-return

Category

style

Advantage

More concise

Drawbacks

No response

Example

let n = match some_option {
    Some(n) => n,
    None => return something_else,
};

Or

let n = if let Some(n) = some_option {
    n
} else {
    return something_else;
};

Could be written as:

let Some(n) = some_option else {
    return something_else,
};

Ideally this would also work with Result.

@frewsxcv frewsxcv added the A-lint Area: New lints label Oct 29, 2022
@frewsxcv frewsxcv changed the title Suggest let...else with return over match with return Suggest let...else with return over match with return Oct 29, 2022
@est31
Copy link
Member

est31 commented Oct 30, 2022

I think you are looking for #8437. It is not in nightly yet, but will be after the the next clippy bump.

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

2 participants