Skip to content

Conversation

@A4-Tacks
Copy link
Member

@A4-Tacks A4-Tacks commented Sep 30, 2025

Example

fn main() {
    if$0 let Ok(x) = Err(92)
        && let Ok(y) = Ok(37)
        && x < 30
        && let Some(y) = Some(8)
    {
        foo(x, y);
    }
}

Before this PR:

fn main() {
    let Ok(x) = Err(92) else { return };
    if !(let Ok(y) = Ok(37) && x < 30) {
        return;
    }
    let Some(y) = Some(8) else { return };
    foo(x, y);
}

After this PR:

fn main() {
    let Ok(x) = Err(92) else { return };
    let Ok(y) = Ok(37) else { return };
    if x >= 30 {
        return;
    }
    let Some(y) = Some(8) else { return };
    foo(x, y);
}

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 30, 2025
@A4-Tacks A4-Tacks force-pushed the fix-guarded-rhs-let-else branch from 03af4ec to e23d6fd Compare September 30, 2025 05:14
Example
---
```rust
fn main() {
    if$0 let Ok(x) = Err(92)
        && let Ok(y) = Ok(37)
        && x < 30
        && let Some(y) = Some(8)
    {
        foo(x, y);
    }
}
```

**Before this PR**:

```rust
fn main() {
    let Ok(x) = Err(92) else { return };
    if !(let Ok(y) = Ok(37) && x < 30) {
        return;
    }
    let Some(y) = Some(8) else { return };
    foo(x, y);
}
```

**After this PR**:

```rust
fn main() {
    let Ok(x) = Err(92) else { return };
    let Ok(y) = Ok(37) else { return };
    if x >= 30 {
        return;
    }
    let Some(y) = Some(8) else { return };
    foo(x, y);
}
```
@A4-Tacks A4-Tacks force-pushed the fix-guarded-rhs-let-else branch from e23d6fd to 9a7afe1 Compare September 30, 2025 05:33
Copy link
Member

@Veykril Veykril left a comment

Choose a reason for hiding this comment

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

thanks!

@Veykril Veykril added this pull request to the merge queue Oct 26, 2025
Merged via the queue into rust-lang:master with commit dcc9af4 Oct 26, 2025
15 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 26, 2025
@lnicola lnicola changed the title Fix let-expr in lhs for convert_to_guarded_return fix: handle if-let in convert_to_guarded_return Oct 26, 2025
@A4-Tacks A4-Tacks deleted the fix-guarded-rhs-let-else branch October 26, 2025 09:27
mendelsshop pushed a commit to mendelsshop/rust-analyzer that referenced this pull request Oct 27, 2025
…else

Fix let-expr in lhs for convert_to_guarded_return
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