Skip to content

fix: no use sad pattern on happy arm with guard#22369

Merged
ChayimFriedman2 merged 1 commit into
rust-lang:masterfrom
A4-Tacks:iflet-with-match-happy-with-guard
May 20, 2026
Merged

fix: no use sad pattern on happy arm with guard#22369
ChayimFriedman2 merged 1 commit into
rust-lang:masterfrom
A4-Tacks:iflet-with-match-happy-with-guard

Conversation

@A4-Tacks
Copy link
Copy Markdown
Member

For replace_if_let_with_match assist

Example

fn foo(x: Option<i32>) {
    $0if let Some(x) = x && x != 4 {
        println!("{}", x)
    } else {
        println!("none")
    }
}

Before this PR

fn foo(x: Option<i32>) {
    match x {
        Some(x) if x != 4 => println!("{}", x),
        None => println!("none"),
    }
}

After this PR

fn foo(x: Option<i32>) {
    match x {
        Some(x) if x != 4 => println!("{}", x),
        _ => println!("none"),
    }
}

For replace_if_let_with_match assist

Example
---
```rust
fn foo(x: Option<i32>) {
    $0if let Some(x) = x && x != 4 {
        println!("{}", x)
    } else {
        println!("none")
    }
}
```

**Before this PR**

```rust
fn foo(x: Option<i32>) {
    match x {
        Some(x) if x != 4 => println!("{}", x),
        None => println!("none"),
    }
}
```

**After this PR**

```rust
fn foo(x: Option<i32>) {
    match x {
        Some(x) if x != 4 => println!("{}", x),
        _ => println!("none"),
    }
}
```
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 15, 2026
@ChayimFriedman2 ChayimFriedman2 added this pull request to the merge queue May 20, 2026
Merged via the queue into rust-lang:master with commit b94da5d May 20, 2026
18 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants