@@ -116,7 +116,7 @@ pub fn format_expr(
116116 rw
117117 } else {
118118 let prefix = block_prefix ( context, block, shape) ?;
119- rewrite_block_with_visitor ( context, & prefix, block, shape)
119+ rewrite_block_with_visitor ( context, & prefix, block, shape, true )
120120 }
121121 }
122122 ExprType :: SubExpression => block. rewrite ( context, shape) ,
@@ -598,11 +598,12 @@ fn rewrite_single_line_block(
598598 None
599599}
600600
601- fn rewrite_block_with_visitor (
601+ pub fn rewrite_block_with_visitor (
602602 context : & RewriteContext ,
603603 prefix : & str ,
604604 block : & ast:: Block ,
605605 shape : Shape ,
606+ has_braces : bool ,
606607) -> Option < String > {
607608 if let rw @ Some ( _) = rewrite_empty_block ( context, block, shape) {
608609 return rw;
@@ -620,7 +621,7 @@ fn rewrite_block_with_visitor(
620621 ast:: BlockCheckMode :: Default => visitor. last_pos = block. span . lo ( ) ,
621622 }
622623
623- visitor. visit_block ( block, None ) ;
624+ visitor. visit_block ( block, None , has_braces ) ;
624625 Some ( format ! ( "{}{}" , prefix, visitor. buffer) )
625626}
626627
@@ -633,8 +634,9 @@ impl Rewrite for ast::Block {
633634 }
634635
635636 let prefix = block_prefix ( context, self , shape) ?;
637+ let shape = shape. offset_left ( last_line_width ( & prefix) ) ?;
636638
637- let result = rewrite_block_with_visitor ( context, & prefix, self , shape) ;
639+ let result = rewrite_block_with_visitor ( context, & prefix, self , shape, true ) ;
638640 if let Some ( ref result_str) = result {
639641 if result_str. lines ( ) . count ( ) <= 3 {
640642 if let rw @ Some ( _) = rewrite_single_line_block ( context, & prefix, self , shape) {
@@ -1064,7 +1066,8 @@ impl<'a> Rewrite for ControlFlow<'a> {
10641066 } ;
10651067 let mut block_context = context. clone ( ) ;
10661068 block_context. is_if_else_block = self . else_block . is_some ( ) ;
1067- let block_str = rewrite_block_with_visitor ( & block_context, "" , self . block , block_shape) ?;
1069+ let block_str =
1070+ rewrite_block_with_visitor ( & block_context, "" , self . block , block_shape, true ) ?;
10681071
10691072 let mut result = format ! ( "{}{}" , cond_str, block_str) ;
10701073
0 commit comments