rust-lang / rust-lang/rust-clippy

suggets simplifying Err(_), Some(_) or Ok(_) to _ inside match if all options are exhausted

Open
#3,262 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

fn get_result(b: bool) -> Result<(u16, u16), String> {
    if b {
        Ok((42, 1337))
    } else {
        Err("oh no".to_string())
    }
}

fn main() {
    let (_, _) = match get_result(false) {
        Err(_) => (0, 0),
        Ok((x, y)) => (x, y),
    };
    //println!("a: {}, b: {}", a, b);
}

the match of the main function can be simplified to

    let (_, _) = match get_result(false) {
        Ok((x, y)) => (x, y),
        _ => (0,0),
    };

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 reviewing the Rust examples in the issue and the existing match-related lint behavior in rust-clippy. Determine how exhaustive match arms involving Err(), Some(), or Ok(_) should be recognized, then verify that the proposed simplification is reported without affecting non-equivalent matches.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.