Skip to content

fix: offer on other if let for replace_if_let_with_match#22529

Open
A4-Tacks wants to merge 1 commit into
rust-lang:masterfrom
A4-Tacks:iflet-with-match-other-iflet
Open

fix: offer on other if let for replace_if_let_with_match#22529
A4-Tacks wants to merge 1 commit into
rust-lang:masterfrom
A4-Tacks:iflet-with-match-other-iflet

Conversation

@A4-Tacks

@A4-Tacks A4-Tacks commented Jun 5, 2026

Copy link
Copy Markdown
Member

Example

fn foo(state: Option<bool>, enable: Option<bool>) -> i32 {
    if let Some(true) = state {
        1
    } else if let Some(true) = enable {
        2
    } else {
        0
    }
}

Before this PR

Assist not applicable

After this PR

fn foo(state: Option<bool>, enable: Option<bool>) -> i32 {
    match state {
        Some(true) => 1,
        _ if let Some(true) = enable => 2,
        _ => 0,
    }
}

Example
---
```rust
fn foo(state: Option<bool>, enable: Option<bool>) -> i32 {
    if let Some(true) = state {
        1
    } else if let Some(true) = enable {
        2
    } else {
        0
    }
}
```

**Before this PR**

Assist not applicable

**After this PR**

```rust
fn foo(state: Option<bool>, enable: Option<bool>) -> i32 {
    match state {
        Some(true) => 1,
        _ if let Some(true) = enable => 2,
        _ => 0,
    }
}
```
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 5, 2026
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.

2 participants