Skip to content

Conversation

@A4-Tacks
Copy link
Member

@A4-Tacks A4-Tacks commented Aug 26, 2025

  • Support let-chain to guard
  • Fix loses comments
  • Fix bad indentation

Example

fn main() {
    if $0let true = true
        && true
        && false
    {
        code()
    }
}

Before this PR

Assist not applicable

After this PR

fn main() {
    match true {
        true if true
            && false => code(),
        _ => (),
    }
}

pub fn foo(foo: i32) {
    $0if let 1 = foo {
        // some comment
        self.foo();
    } else if let 2 = foo {
        // some comment 2
        self.bar()
    }
}

Before this PR

pub fn foo(foo: i32) {
    match foo {
        1 => {
            self.foo();
        }
        2 => self.bar(),
        _ => (),
    }
}

After this PR

pub fn foo(foo: i32) {
    match foo {
        1 => {
            // some comment
            self.foo();
        }
        2 => {
            // some comment 2
            self.bar()
        },
        _ => (),
    }
}

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 26, 2025
@A4-Tacks A4-Tacks force-pushed the if-let-to-match-guard branch from 1669d88 to 0540e6f Compare September 6, 2025 09:21
- Fix loses comments
- Fix bad indentation

Example
---
```rust
fn main() {
    if $0let true = true
        && true
        && false
    {
        code()
    }
}
```

**Before this PR**

Assist not applicable

**After this PR**

```rust
fn main() {
    match true {
        true if true
            && false => code(),
        _ => (),
    }
}
```

---

```rust
pub fn foo(foo: i32) {
    $0if let 1 = foo {
        // some comment
        self.foo();
    } else if let 2 = foo {
        // some comment 2
        self.bar()
    }
}
```

**Before this PR**

```rust
pub fn foo(foo: i32) {
    match foo {
        1 => {
            self.foo();
        }
        2 => self.bar(),
        _ => (),
    }
}
```

**After this PR**

```rust
pub fn foo(foo: i32) {
    match foo {
        1 => {
            // some comment
            self.foo();
        }
        2 => {
            // some comment 2
            self.bar()
        },
        _ => (),
    }
}
```
@A4-Tacks A4-Tacks force-pushed the if-let-to-match-guard branch from 0540e6f to f96a01b Compare November 7, 2025 02:48
@A4-Tacks
Copy link
Member Author

A4-Tacks commented Nov 7, 2025

r? @ShoyuVanilla

@ShoyuVanilla ShoyuVanilla added this pull request to the merge queue Nov 10, 2025
Merged via the queue into rust-lang:master with commit 73f565e Nov 10, 2025
15 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 10, 2025
@A4-Tacks A4-Tacks deleted the if-let-to-match-guard branch November 10, 2025 07:21
@lnicola lnicola changed the title Add guard support for replace_if_let_with_match fix: handle guards in replace_if_let_with_match Nov 10, 2025
lnicola pushed a commit to lnicola/rust-analyzer that referenced this pull request Nov 11, 2025
Add guard support for replace_if_let_with_match
lnicola pushed a commit to lnicola/rust-analyzer that referenced this pull request Nov 11, 2025
Add guard support for replace_if_let_with_match
lnicola pushed a commit to lnicola/rust-analyzer that referenced this pull request Nov 15, 2025
Add guard support for replace_if_let_with_match
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