Skip to content

feat: handle if matches!() for replace_if_let_with_match#22079

Open
A4-Tacks wants to merge 2 commits intorust-lang:masterfrom
A4-Tacks:if-matches-with-match
Open

feat: handle if matches!() for replace_if_let_with_match#22079
A4-Tacks wants to merge 2 commits intorust-lang:masterfrom
A4-Tacks:if-matches-with-match

Conversation

@A4-Tacks
Copy link
Copy Markdown
Member

@A4-Tacks A4-Tacks commented Apr 18, 2026

Close #20013

Example

fn foo(x: Result<i32, ()>) {
    $0if matches!(x, Ok(a @ 1..2)) {
    }
}

Before this PR

fn foo(x: Result<i32, ()>) {
    match matches!(x, Ok(a @ 1..2)) {
        true => {}
        false => (),
    }
}

After this PR

fn foo(x: Result<i32, ()>) {
    match x {
        Ok(a@1..2) => {}
        _ => (),
    }
}

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 18, 2026
@A4-Tacks A4-Tacks force-pushed the if-matches-with-match branch from 46ab9fe to d187af3 Compare April 18, 2026 05:21
Example
---
```rust
fn foo(x: Result<i32, ()>) {
    $0if matches!(x, Ok(a @ 1..2)) {
    }
}
```

**Before this PR**

```rust
fn foo(x: Result<i32, ()>) {
    match matches!(x, Ok(a @ 1..2)) {
        true => {}
        false => (),
    }
}
```

**After this PR**

```rust
fn foo(x: Result<i32, ()>) {
    match x {
        Ok(a@1..2) => {}
        _ => (),
    }
}
```
@A4-Tacks A4-Tacks force-pushed the if-matches-with-match branch from d187af3 to 9e61113 Compare April 18, 2026 06:19
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.

assist: Replace if matches!(..) with match expr

2 participants