fix panic on closure with empty block expr (#3846)

This commit is contained in:
Caleb Cartwright 2019-10-07 21:00:31 -05:00 committed by Seiichi Uchida
parent 6dcbc5d78e
commit 207a58f365
3 changed files with 9 additions and 2 deletions

View file

@ -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);
}
}

View file

@ -0,0 +1,3 @@
fn main() {
|| {{}};
}

View file

@ -0,0 +1,3 @@
fn main() {
|| {};
}