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

Match return option followed by return in case of None #9554

Open
AurelienFT opened this issue Sep 29, 2022 · 0 comments
Open

Match return option followed by return in case of None #9554

AurelienFT opened this issue Sep 29, 2022 · 0 comments
Labels
A-lint Area: New lints

Comments

@AurelienFT
Copy link
Contributor

What it does

This lint can flag match that return option and that are directly followed by a return in case of None with/without error mapping. They could be factorized to not return an option and return directly the error he is mapped to.

Lint Name

match_return_too_complex

Category

style, complexity

Advantage

  • Simplify the code by removing a combinator call

Drawbacks

No response

Example

let a = match self.block_statuses.get(&cur_h) {
    Some(block) => Some(block.id),
     _ => None,
}.ok_or_else(|| "Error".to_string())?;

Could be written as:

let a = match self.block_statuses.get(&cur_h) {
    Some(block) => block.id,
     _ => return Err("Error".to_string()),
};
@AurelienFT AurelienFT added the A-lint Area: New lints label Sep 29, 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