Skip to content

feat: Add unwrap_block, offer unwrap_block and unwrap_branch#22179

Merged
ChayimFriedman2 merged 1 commit into
rust-lang:masterfrom
A4-Tacks:pure-unwrap-block
Apr 26, 2026
Merged

feat: Add unwrap_block, offer unwrap_block and unwrap_branch#22179
ChayimFriedman2 merged 1 commit into
rust-lang:masterfrom
A4-Tacks:pure-unwrap-block

Conversation

@A4-Tacks

@A4-Tacks A4-Tacks commented Apr 25, 2026

Copy link
Copy Markdown
Member

Close #13747

Example

fn main() {
    match rel_path {
        Ok(rel_path) => {$0
            if true {
                foo()
            }
        }
        Err(_) => None,
    }
}

Before this PR

Unwrap branch

After this PR

Unwrap branch
Unwrap block
fn main() {
    match rel_path {
        Ok(rel_path) => if true {
            foo()
        }
        Err(_) => None,
    }
}

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 25, 2026
@A4-Tacks A4-Tacks marked this pull request as draft April 26, 2026 06:35
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 26, 2026
Example
---
```rust
fn main() {
    match rel_path {
        Ok(rel_path) => {$0
            if true {
                foo()
            }
        }
        Err(_) => None,
    }
}
```

**Before this PR**

```text
Unwrap branch
```

**After this PR**

```text
Unwrap branch
Unwrap block
```

```rust
fn main() {
    match rel_path {
        Ok(rel_path) => if true {
            foo()
        }
        Err(_) => None,
    }
}
```
@A4-Tacks A4-Tacks force-pushed the pure-unwrap-block branch from f92faaf to fcd9a26 Compare April 26, 2026 07:04
@A4-Tacks A4-Tacks marked this pull request as ready for review April 26, 2026 07:04
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 26, 2026
let target = block.syntax().text_range();
let tail_expr = block.tail_expr()?;
let stmt_list = block.stmt_list()?;
let container = Either::<ast::MatchArm, ast::ClosureExpr>::cast(block.syntax().parent()?)?;

@ChayimFriedman2 ChayimFriedman2 Apr 26, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Won't closures also have "Unwrap block" from the unwrap_branch assist?

View changes since the review

@A4-Tacks A4-Tacks Apr 26, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

unwrap_branch only unwrap branches and does not include ClosureExpr

@ChayimFriedman2 ChayimFriedman2 added this pull request to the merge queue Apr 26, 2026
Merged via the queue into rust-lang:master with commit 9006fee Apr 26, 2026
18 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 26, 2026
@A4-Tacks A4-Tacks deleted the pure-unwrap-block branch April 26, 2026 12:05
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.

Unwrap block removes match expression

3 participants