Skip to content

Commit 75c5142

Browse files
committed
chore: make rewrite_closure_block accept Expr and pass the entire body
1 parent 2b88689 commit 75c5142

File tree

1 file changed

+8
-18
lines changed

1 file changed

+8
-18
lines changed

src/closures.rs

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub(crate) fn rewrite_closure(
5555
// 1 = space between `|...|` and body.
5656
let body_shape = shape.offset_left(extra_offset, span)?;
5757

58-
if let ast::ExprKind::Block(ref block, ref label) = body.kind {
58+
if let ast::ExprKind::Block(ref block, _) = body.kind {
5959
// The body of the closure is an empty block.
6060
if block.stmts.is_empty() && !block_contains_comment(context, block) {
6161
return body
@@ -72,7 +72,7 @@ pub(crate) fn rewrite_closure(
7272

7373
result.or_else(|_| {
7474
// Either we require a block, or tried without and failed.
75-
rewrite_closure_block(block, label, &prefix, context, body_shape)
75+
rewrite_closure_block(body, &prefix, context, body_shape)
7676
})
7777
} else {
7878
rewrite_closure_expr(body, &prefix, context, body_shape).or_else(|_| {
@@ -236,26 +236,16 @@ fn rewrite_closure_expr(
236236

237237
// Rewrite closure whose body is block.
238238
fn rewrite_closure_block(
239-
block: &ast::Block,
240-
label: &Option<Label>,
239+
block: &ast::Expr,
241240
prefix: &str,
242241
context: &RewriteContext<'_>,
243242
shape: Shape,
244243
) -> RewriteResult {
245-
if let Some(label) = label {
246-
Ok(format!(
247-
"{} {}: {}",
248-
prefix,
249-
context.snippet(label.ident.span),
250-
block.rewrite_result(context, shape)?
251-
))
252-
} else {
253-
Ok(format!(
254-
"{} {}",
255-
prefix,
256-
block.rewrite_result(context, shape)?
257-
))
258-
}
244+
Ok(format!(
245+
"{} {}",
246+
prefix,
247+
block.rewrite_result(context, shape)?
248+
))
259249
}
260250

261251
// Return type is (prefix, extra_offset)

0 commit comments

Comments
 (0)