Skip to content

Commit

Permalink
fix panic on closure with empty block expr (rust-lang#3846)
Browse files Browse the repository at this point in the history
  • Loading branch information
calebcartwright authored and topecongiro committed Oct 8, 2019
1 parent 6dcbc5d commit 207a58f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/closures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ fn get_inner_expr<'a>(
) -> &'a ast::Expr {
if let ast::ExprKind::Block(ref block, _) = expr.kind {
if !needs_block(block, prefix, context) {
// block.stmts.len() == 1
if let Some(expr) = stmt_expr(&block.stmts[0]) {
// block.stmts.len() == 1 except with `|| {{}}`;
// https://github.com/rust-lang/rustfmt/issues/3844
if let Some(expr) = block.stmts.first().and_then(stmt_expr) {
return get_inner_expr(expr, prefix, context);
}
}
Expand Down
3 changes: 3 additions & 0 deletions tests/source/issue_3844.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
|| {{}};
}
3 changes: 3 additions & 0 deletions tests/target/issue_3844.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
|| {};
}

0 comments on commit 207a58f

Please sign in to comment.