Skip to content

Conversation

A4-Tacks
Copy link
Contributor

Add support for else-block of never-type for convert_to_guarded_return

Example

fn main() {
    if$0 let Ok(x) = Err(92) {
        foo(x);
    } else {
        return
    }
}

Before this PR:

Assist not applicable

After this PR:

fn main() {
    let Ok(x) = Err(92) else {
        return
    };
    foo(x);
}

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 27, 2025
Add support for else-block of never-type for `convert_to_guarded_return`

Example
---
```rust
fn main() {
    if$0 let Ok(x) = Err(92) {
        foo(x);
    } else {
        return
    }
}
```

**Before this PR**:

Assist not applicable

**After this PR**:

```rust
fn main() {
    let Ok(x) = Err(92) else {
        return
    };
    foo(x);
}
```
// if !cond {
// return;
// }
// if !cond { return }
Copy link
Member

Choose a reason for hiding this comment

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

Looks good overall but I think we'd prefer the former return; stmt over { return } as rustfmt does so

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will make it more compact in let-chain

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.

3 participants