Skip to content

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

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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