Skip to content

Suggest if let in more cases#17067

Open
koenw wants to merge 2 commits into
rust-lang:masterfrom
koenw:2567
Open

Suggest if let in more cases#17067
koenw wants to merge 2 commits into
rust-lang:masterfrom
koenw:2567

Conversation

@koenw
Copy link
Copy Markdown

@koenw koenw commented May 23, 2026

Given the following Clippy currently doesn't trigger a single_match lint:

match x {
    Ok(_) => {},
    Err(a) => { do_something(a) },
}

whereas Clippy does trigger a single_match lint if the arms are switched around:

match x {
    Err(a) => { do_something(a) },
    Ok(_) => {},
}

This commit updates the single_match lint to trigger in both cases.

changelog: [single_match]: Suggest if let in more cases

Possibly fixes #2567 (If I understand the issue correctly).

Given the following Clippy currently doesn't trigger a `single_match` lint:

```rust
match x {
    Ok(_) => {},
    Err(a) => { do_something(a) },
}
```

whereas Clippy *does* trigger a `single_match` lint if the arms are switched around:

```rust
match x {
    Err(a) => { do_something(a) },
    Ok(_) => {},
}
```

This commit updates the `single_match` lint to trigger in both cases.
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label May 23, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 23, 2026

r? @samueltardieu

rustbot has assigned @samueltardieu.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: 7 candidates
  • 7 candidates expanded to 7 candidates
  • Random selection from Jarcho, llogiq, samueltardieu

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 23, 2026

Lintcheck changes for dc5d818

Lint Added Removed Changed
clippy::single_match 2 0 0
clippy::single_match_else 24 0 1

This comment will be updated if you push new changes

@koenw
Copy link
Copy Markdown
Author

koenw commented May 23, 2026

So stupidly I forgot to run the tests without TESTNAME=single_match and apparently some other tests broke that I will now investigate :)

This commit updates the `infinite_loops` and `ref_patterns` tests to not
trigger the newly updated `single_match` lint.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties

Projects

None yet

Development

Successfully merging this pull request may close these issues.

single_match: recongnize "Ok(_) => {}" or "Err(_bla) => {}" as "_ => {}"

3 participants