@@ -462,7 +462,7 @@ fn rewrite_empty_block(
462
462
return None ;
463
463
}
464
464
465
- let label_str = rewrite_label ( label) ;
465
+ let label_str = rewrite_label ( context , label) ;
466
466
if attrs. map_or ( false , |a| !inner_attributes ( a) . is_empty ( ) ) {
467
467
return None ;
468
468
}
@@ -527,7 +527,7 @@ fn rewrite_single_line_block(
527
527
if let Some ( block_expr) = stmt:: Stmt :: from_simple_block ( context, block, attrs) {
528
528
let expr_shape = shape. offset_left ( last_line_width ( prefix) ) ?;
529
529
let expr_str = block_expr. rewrite ( context, expr_shape) ?;
530
- let label_str = rewrite_label ( label) ;
530
+ let label_str = rewrite_label ( context , label) ;
531
531
let result = format ! ( "{prefix}{label_str}{{ {expr_str} }}" ) ;
532
532
if result. len ( ) <= shape. width && !result. contains ( '\n' ) {
533
533
return Some ( result) ;
@@ -562,7 +562,7 @@ pub(crate) fn rewrite_block_with_visitor(
562
562
}
563
563
564
564
let inner_attrs = attrs. map ( inner_attributes) ;
565
- let label_str = rewrite_label ( label) ;
565
+ let label_str = rewrite_label ( context , label) ;
566
566
visitor. visit_block ( block, inner_attrs. as_deref ( ) , has_braces) ;
567
567
let visitor_context = visitor. get_context ( ) ;
568
568
context
@@ -939,7 +939,7 @@ impl<'a> ControlFlow<'a> {
939
939
fresh_shape
940
940
} ;
941
941
942
- let label_string = rewrite_label ( self . label ) ;
942
+ let label_string = rewrite_label ( context , self . label ) ;
943
943
// 1 = space after keyword.
944
944
let offset = self . keyword . len ( ) + label_string. len ( ) + 1 ;
945
945
@@ -1168,9 +1168,9 @@ impl<'a> Rewrite for ControlFlow<'a> {
1168
1168
}
1169
1169
}
1170
1170
1171
- fn rewrite_label ( opt_label : Option < ast:: Label > ) -> Cow < ' static , str > {
1171
+ fn rewrite_label ( context : & RewriteContext < ' _ > , opt_label : Option < ast:: Label > ) -> Cow < ' static , str > {
1172
1172
match opt_label {
1173
- Some ( label) => Cow :: from ( format ! ( "{}: " , label. ident) ) ,
1173
+ Some ( label) => Cow :: from ( format ! ( "{}: " , context . snippet ( label. ident. span ) ) ) ,
1174
1174
None => Cow :: from ( "" ) ,
1175
1175
}
1176
1176
}
0 commit comments