@@ -387,23 +387,23 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
387
387
self . print_string ( sym. as_str ( ) , style) ;
388
388
}
389
389
390
- fn print_inner_attributes ( & mut self , attrs : & [ ast:: Attribute ] ) {
390
+ fn print_inner_attributes ( & mut self , attrs : & [ ast:: Attribute ] ) -> bool {
391
391
self . print_either_attributes ( attrs, ast:: AttrStyle :: Inner , false , true )
392
392
}
393
393
394
- fn print_inner_attributes_no_trailing_hardbreak ( & mut self , attrs : & [ ast:: Attribute ] ) {
394
+ fn print_inner_attributes_no_trailing_hardbreak ( & mut self , attrs : & [ ast:: Attribute ] ) -> bool {
395
395
self . print_either_attributes ( attrs, ast:: AttrStyle :: Inner , false , false )
396
396
}
397
397
398
- fn print_outer_attributes ( & mut self , attrs : & [ ast:: Attribute ] ) {
398
+ fn print_outer_attributes ( & mut self , attrs : & [ ast:: Attribute ] ) -> bool {
399
399
self . print_either_attributes ( attrs, ast:: AttrStyle :: Outer , false , true )
400
400
}
401
401
402
- fn print_inner_attributes_inline ( & mut self , attrs : & [ ast:: Attribute ] ) {
402
+ fn print_inner_attributes_inline ( & mut self , attrs : & [ ast:: Attribute ] ) -> bool {
403
403
self . print_either_attributes ( attrs, ast:: AttrStyle :: Inner , true , true )
404
404
}
405
405
406
- fn print_outer_attributes_inline ( & mut self , attrs : & [ ast:: Attribute ] ) {
406
+ fn print_outer_attributes_inline ( & mut self , attrs : & [ ast:: Attribute ] ) -> bool {
407
407
self . print_either_attributes ( attrs, ast:: AttrStyle :: Outer , true , true )
408
408
}
409
409
@@ -413,20 +413,21 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
413
413
kind : ast:: AttrStyle ,
414
414
is_inline : bool ,
415
415
trailing_hardbreak : bool ,
416
- ) {
417
- let mut count = 0 ;
416
+ ) -> bool {
417
+ let mut printed = false ;
418
418
for attr in attrs {
419
419
if attr. style == kind {
420
420
self . print_attribute_inline ( attr, is_inline) ;
421
421
if is_inline {
422
422
self . nbsp ( ) ;
423
423
}
424
- count += 1 ;
424
+ printed = true ;
425
425
}
426
426
}
427
- if count > 0 && trailing_hardbreak && !is_inline {
427
+ if printed && trailing_hardbreak && !is_inline {
428
428
self . hardbreak_if_not_bol ( ) ;
429
429
}
430
+ printed
430
431
}
431
432
432
433
fn print_attribute ( & mut self , attr : & ast:: Attribute ) {
@@ -1646,7 +1647,7 @@ impl<'a> State<'a> {
1646
1647
self . ann . pre ( self , AnnNode :: Block ( blk) ) ;
1647
1648
self . bopen ( ) ;
1648
1649
1649
- self . print_inner_attributes ( attrs) ;
1650
+ let has_attrs = self . print_inner_attributes ( attrs) ;
1650
1651
1651
1652
for ( i, st) in blk. stmts . iter ( ) . enumerate ( ) {
1652
1653
match st. kind {
@@ -1660,7 +1661,7 @@ impl<'a> State<'a> {
1660
1661
}
1661
1662
}
1662
1663
1663
- let empty = attrs . is_empty ( ) && blk. stmts . is_empty ( ) ;
1664
+ let empty = !has_attrs && blk. stmts . is_empty ( ) ;
1664
1665
self . bclose_maybe_open ( blk. span , empty, close_box) ;
1665
1666
self . ann . post ( self , AnnNode :: Block ( blk) )
1666
1667
}
0 commit comments