Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 207a58f

Browse files
calebcartwrighttopecongiro
authored andcommitted
fix panic on closure with empty block expr (rust-lang#3846)
1 parent 6dcbc5d commit 207a58f

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

src/closures.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,9 @@ fn get_inner_expr<'a>(
9191
) -> &'a ast::Expr {
9292
if let ast::ExprKind::Block(ref block, _) = expr.kind {
9393
if !needs_block(block, prefix, context) {
94-
// block.stmts.len() == 1
95-
if let Some(expr) = stmt_expr(&block.stmts[0]) {
94+
// block.stmts.len() == 1 except with `|| {{}}`;
95+
// https://github.com/rust-lang/rustfmt/issues/3844
96+
if let Some(expr) = block.stmts.first().and_then(stmt_expr) {
9697
return get_inner_expr(expr, prefix, context);
9798
}
9899
}

tests/source/issue_3844.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
|| {{}};
3+
}

tests/target/issue_3844.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
|| {};
3+
}

0 commit comments

Comments
 (0)