@@ -118,19 +118,19 @@ pub fn format_expr(
118
118
| ast:: ExprKind :: While ( ..)
119
119
| ast:: ExprKind :: WhileLet ( ..) => to_control_flow ( expr, expr_type)
120
120
. and_then ( |control_flow| control_flow. rewrite ( context, shape) ) ,
121
- // FIXME(topecongiro): Handle label on a block (#2722).
122
- ast:: ExprKind :: Block ( ref block, _) => {
121
+ ast:: ExprKind :: Block ( ref block, opt_label) => {
123
122
match expr_type {
124
123
ExprType :: Statement => {
125
124
if is_unsafe_block ( block) {
126
- rewrite_block ( block, Some ( & expr. attrs ) , context, shape)
125
+ rewrite_block ( block, Some ( & expr. attrs ) , opt_label , context, shape)
127
126
} else if let rw @ Some ( _) =
128
127
rewrite_empty_block ( context, block, Some ( & expr. attrs ) , "" , shape)
129
128
{
130
129
// Rewrite block without trying to put it in a single line.
131
130
rw
132
131
} else {
133
132
let prefix = block_prefix ( context, block, shape) ?;
133
+
134
134
rewrite_block_with_visitor (
135
135
context,
136
136
& prefix,
@@ -141,7 +141,9 @@ pub fn format_expr(
141
141
)
142
142
}
143
143
}
144
- ExprType :: SubExpression => rewrite_block ( block, Some ( & expr. attrs ) , context, shape) ,
144
+ ExprType :: SubExpression => {
145
+ rewrite_block ( block, Some ( & expr. attrs ) , opt_label, context, shape)
146
+ }
145
147
}
146
148
}
147
149
ast:: ExprKind :: Match ( ref cond, ref arms) => {
@@ -327,6 +329,7 @@ pub fn format_expr(
327
329
rewrite_block(
328
330
block,
329
331
Some ( & expr. attrs) ,
332
+ None ,
330
333
context,
331
334
Shape :: legacy( budget, shape. indent)
332
335
) ?
@@ -644,17 +647,20 @@ pub fn rewrite_block_with_visitor(
644
647
645
648
impl Rewrite for ast:: Block {
646
649
fn rewrite ( & self , context : & RewriteContext , shape : Shape ) -> Option < String > {
647
- rewrite_block ( self , None , context, shape)
650
+ rewrite_block ( self , None , None , context, shape)
648
651
}
649
652
}
650
653
651
654
fn rewrite_block (
652
655
block : & ast:: Block ,
653
656
attrs : Option < & [ ast:: Attribute ] > ,
657
+ label : Option < ast:: Label > ,
654
658
context : & RewriteContext ,
655
659
shape : Shape ,
656
660
) -> Option < String > {
657
- let prefix = block_prefix ( context, block, shape) ?;
661
+ let unsafe_string = block_prefix ( context, block, shape) ?;
662
+ let label_string = rewrite_label ( label) ;
663
+ let prefix = format ! ( "{}{}" , unsafe_string, label_string) ;
658
664
659
665
// shape.width is used only for the single line case: either the empty block `{}`,
660
666
// or an unsafe expression `unsafe { e }`.
0 commit comments