Skip to content

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

Closed
@frewsxcv

Description

@frewsxcv

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.

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