rust-lang / rust-lang/rust-clippy

useless destructive match

Open
#8,980 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
pub fn a(x: Option<i32>) -> Option<i32> {
    if let Some(x) = x {
        return Some(x);
    }
    // could just be be:
    if x.is_some() {
       return x
    }

     // could probably lint Result<> as well, bot sure about any enum container in general though
    todo!()
}

pub fn b(x: Option<i32>) -> Option<i32> {
    return match x {
        Some(x) => Some(x),
        _ => todo!(),
    };
    // could be:, but if-let is probably more idiomatic 
    return match x {
        None => todo!(),
        x => x, 
    };

    }
```

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 comparing the Rust examples for the proposed if let and match patterns and determine the intended lint scope, including whether Result or other enum containers are covered. No source file or test is named; done would require an agreed scope and corresponding lint behavior and tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.