rust-lang / rust-lang/rust-clippy

Slight improvement for suggesting `is_ok()` and `is_err()` instead of `matches!()`

Open
#10,050 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Description

This is a very minor enhancement suggestion. I just found very old code that looked like this:

pub fn test(r: Result<(), ()>) -> bool {
    match r {
        Ok(_) => true,
        _ => false,
    }
}

Instead of pointing the user to is_ok() clippy had the following output:

warning: match expression looks like `matches!` macro
 --> src/main.rs:4:5
  |
4 | /     match r {
5 | |         Ok(_) => true,
6 | |         _ => false,
7 | |     }
  | |_____^ help: try this: `matches!(r, Ok(_))`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_like_matches_macro
  = note: `#[warn(clippy::match_like_matches_macro)]` on by default
Version
rustc 1.67.0-nightly (2585bcea0 2022-11-28)
binary: rustc
commit-hash: 2585bcea0bc2a9c42a4be2c1eba5c61137f2b167
commit-date: 2022-11-28
host: x86_64-unknown-linux-gnu
release: 1.67.0-nightly
LLVM version: 15.0.4
Additional Labels

@rustbot label +C-enhancement

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

The relevant entry point is the match_like_matches_macro lint named in the report; start by locating its implementation and existing tests. Compare its diagnostic with the requested is_ok()/is_err() suggestion, then verify the intended cases in the lint test suite.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.