diff --git a/src/closures.rs b/src/closures.rs index 1f59fbc2960..296b7407e40 100644 --- a/src/closures.rs +++ b/src/closures.rs @@ -1,4 +1,4 @@ -use rustc_ast::{ast, ptr}; +use rustc_ast::{Label, ast, ptr}; use rustc_span::Span; use thin_vec::thin_vec; use tracing::debug; @@ -72,7 +72,7 @@ pub(crate) fn rewrite_closure( result.or_else(|_| { // Either we require a block, or tried without and failed. - rewrite_closure_block(block, &prefix, context, body_shape) + rewrite_closure_block(body, &prefix, context, body_shape) }) } else { rewrite_closure_expr(body, &prefix, context, body_shape).or_else(|_| { @@ -104,8 +104,8 @@ fn get_inner_expr<'a>( prefix: &str, context: &RewriteContext<'_>, ) -> &'a ast::Expr { - if let ast::ExprKind::Block(ref block, _) = expr.kind { - if !needs_block(block, prefix, context) { + if let ast::ExprKind::Block(ref block, ref label) = expr.kind { + if !needs_block(block, label, prefix, context) { // 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) { @@ -118,7 +118,12 @@ fn get_inner_expr<'a>( } // Figure out if a block is necessary. -fn needs_block(block: &ast::Block, prefix: &str, context: &RewriteContext<'_>) -> bool { +fn needs_block( + block: &ast::Block, + label: &Option