@@ -387,23 +387,23 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
387387 self . print_string ( sym. as_str ( ) , style) ;
388388 }
389389
390- fn print_inner_attributes ( & mut self , attrs : & [ ast:: Attribute ] ) {
390+ fn print_inner_attributes ( & mut self , attrs : & [ ast:: Attribute ] ) -> bool {
391391 self . print_either_attributes ( attrs, ast:: AttrStyle :: Inner , false , true )
392392 }
393393
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 {
395395 self . print_either_attributes ( attrs, ast:: AttrStyle :: Inner , false , false )
396396 }
397397
398- fn print_outer_attributes ( & mut self , attrs : & [ ast:: Attribute ] ) {
398+ fn print_outer_attributes ( & mut self , attrs : & [ ast:: Attribute ] ) -> bool {
399399 self . print_either_attributes ( attrs, ast:: AttrStyle :: Outer , false , true )
400400 }
401401
402- fn print_inner_attributes_inline ( & mut self , attrs : & [ ast:: Attribute ] ) {
402+ fn print_inner_attributes_inline ( & mut self , attrs : & [ ast:: Attribute ] ) -> bool {
403403 self . print_either_attributes ( attrs, ast:: AttrStyle :: Inner , true , true )
404404 }
405405
406- fn print_outer_attributes_inline ( & mut self , attrs : & [ ast:: Attribute ] ) {
406+ fn print_outer_attributes_inline ( & mut self , attrs : & [ ast:: Attribute ] ) -> bool {
407407 self . print_either_attributes ( attrs, ast:: AttrStyle :: Outer , true , true )
408408 }
409409
@@ -413,20 +413,21 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
413413 kind : ast:: AttrStyle ,
414414 is_inline : bool ,
415415 trailing_hardbreak : bool ,
416- ) {
417- let mut count = 0 ;
416+ ) -> bool {
417+ let mut printed = false ;
418418 for attr in attrs {
419419 if attr. style == kind {
420420 self . print_attribute_inline ( attr, is_inline) ;
421421 if is_inline {
422422 self . nbsp ( ) ;
423423 }
424- count += 1 ;
424+ printed = true ;
425425 }
426426 }
427- if count > 0 && trailing_hardbreak && !is_inline {
427+ if printed && trailing_hardbreak && !is_inline {
428428 self . hardbreak_if_not_bol ( ) ;
429429 }
430+ printed
430431 }
431432
432433 fn print_attribute ( & mut self , attr : & ast:: Attribute ) {
@@ -1646,7 +1647,7 @@ impl<'a> State<'a> {
16461647 self . ann . pre ( self , AnnNode :: Block ( blk) ) ;
16471648 self . bopen ( ) ;
16481649
1649- self . print_inner_attributes ( attrs) ;
1650+ let has_attrs = self . print_inner_attributes ( attrs) ;
16501651
16511652 for ( i, st) in blk. stmts . iter ( ) . enumerate ( ) {
16521653 match st. kind {
@@ -1660,7 +1661,7 @@ impl<'a> State<'a> {
16601661 }
16611662 }
16621663
1663- let empty = attrs . is_empty ( ) && blk. stmts . is_empty ( ) ;
1664+ let empty = !has_attrs && blk. stmts . is_empty ( ) ;
16641665 self . bclose_maybe_open ( blk. span , empty, close_box) ;
16651666 self . ann . post ( self , AnnNode :: Block ( blk) )
16661667 }
0 commit comments