Skip to content

Support else-branch for move_guard#21508

Merged
ChayimFriedman2 merged 3 commits intorust-lang:masterfrom
A4-Tacks:move-guard-else-if
Feb 3, 2026
Merged

Support else-branch for move_guard#21508
ChayimFriedman2 merged 3 commits intorust-lang:masterfrom
A4-Tacks:move-guard-else-if

Conversation

@A4-Tacks
Copy link
Member

Example

fn main() {
    match 92 {
        x @ 0..30 $0if x % 3 == 0 => false,
        x @ 0..30 if x % 2 == 0 => true,
        _ => false
    }
}

Before this PR

fn main() {
    match 92 {
        x @ 0..30 => if x % 3 == 0 {
            false
        },
        x @ 0..30 if x % 2 == 0 => true,
        _ => false
    }
}

After this PR

fn main() {
    match 92 {
        x @ 0..30 => if x % 3 == 0 {
            false
        } else if x % 2 == 0 {
            true
        },
        _ => false
    }
}

Example
---
```rust
fn main() {
    match 92 {
        x @ 0..30 $0if x % 3 == 0 => false,
        x @ 0..30 if x % 2 == 0 => true,
        _ => false
    }
}
```

**Before this PR**

```rust
fn main() {
    match 92 {
        x @ 0..30 => if x % 3 == 0 {
            false
        },
        x @ 0..30 if x % 2 == 0 => true,
        _ => false
    }
}
```

**After this PR**

```rust
fn main() {
    match 92 {
        x @ 0..30 => if x % 3 == 0 {
            false
        } else if x % 2 == 0 {
            true
        },
        _ => false
    }
}
```
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 22, 2026
Copy link
Contributor

@ChayimFriedman2 ChayimFriedman2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will transform the code wrongly if the user is selecting the non-first arm.

Other than that, LGTM.

@A4-Tacks
Copy link
Member Author

This will transform the code wrongly if the user is selecting the non-first arm.

From testing, it is expected

@ChayimFriedman2
Copy link
Contributor

I meant where there is an empty selection, so all matching arms are eligible, but we'll reorder them to put the arm where the cursor is first.

@A4-Tacks
Copy link
Member Author

I meant where there is an empty selection, so all matching arms are eligible

Why are we doing this? The current logic is consistent with Merge match arms

@ChayimFriedman2
Copy link
Contributor

Okay, I see now. I think this isn't the best behavior but since it's consistent, LGTM.

Thanks!

@ChayimFriedman2 ChayimFriedman2 added this pull request to the merge queue Feb 3, 2026
github-merge-queue bot pushed a commit that referenced this pull request Feb 3, 2026
Support else-branch for move_guard
Merged via the queue into rust-lang:master with commit a84d92f Feb 3, 2026
15 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 3, 2026
@A4-Tacks A4-Tacks deleted the move-guard-else-if branch February 3, 2026 09:48
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