Skip to content

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

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

fix: no use sad pattern on happy arm with guard#22369
A4-Tacks wants to merge 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
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