rust-lang / rust-lang/rust-clippy

Match return option followed by return in case of None

Open
#9,554 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-lint
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

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()),
};

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the implementation and tests for the match_return_too_complex lint, then compare them with the issue's Some/None example. Done means the lint recognizes matches that immediately convert an optional result into an error and supports the direct-return form without flagging unrelated matches.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.