@@ -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 }
@@ -2780,34 +2781,34 @@ impl<'a> State<'a> {
27802781 self . word_space ( "," ) ;
27812782 }
27822783
2783- match * predicate {
2784- ast :: WherePredicate :: BoundPredicate ( ast :: WhereBoundPredicate {
2785- ref bound_generic_params ,
2786- ref bounded_ty ,
2787- ref bounds ,
2788- ..
2789- } ) => {
2790- self . print_formal_generic_params ( bound_generic_params) ;
2791- self . print_type ( bounded_ty) ;
2792- self . print_type_bounds ( ":" , bounds) ;
2793- }
2794- ast :: WherePredicate :: RegionPredicate ( ast :: WhereRegionPredicate {
2795- ref lifetime ,
2796- ref bounds ,
2797- ..
2798- } ) => {
2799- self . print_lifetime_bounds ( * lifetime , bounds ) ;
2800- }
2801- ast :: WherePredicate :: EqPredicate ( ast :: WhereEqPredicate {
2802- ref lhs_ty ,
2803- ref rhs_ty ,
2804- ..
2805- } ) => {
2806- self . print_type ( lhs_ty ) ;
2807- self . space ( ) ;
2808- self . word_space ( "=" ) ;
2809- self . print_type ( rhs_ty ) ;
2810- }
2784+ self . print_where_predicate ( predicate) ;
2785+ }
2786+ }
2787+
2788+ pub fn print_where_predicate ( & mut self , predicate : & ast :: WherePredicate ) {
2789+ match predicate {
2790+ ast :: WherePredicate :: BoundPredicate ( ast :: WhereBoundPredicate {
2791+ bound_generic_params,
2792+ bounded_ty,
2793+ bounds,
2794+ ..
2795+ } ) => {
2796+ self . print_formal_generic_params ( bound_generic_params ) ;
2797+ self . print_type ( bounded_ty ) ;
2798+ self . print_type_bounds ( ":" , bounds ) ;
2799+ }
2800+ ast :: WherePredicate :: RegionPredicate ( ast :: WhereRegionPredicate {
2801+ lifetime ,
2802+ bounds ,
2803+ ..
2804+ } ) => {
2805+ self . print_lifetime_bounds ( * lifetime , bounds ) ;
2806+ }
2807+ ast :: WherePredicate :: EqPredicate ( ast :: WhereEqPredicate { lhs_ty , rhs_ty , .. } ) => {
2808+ self . print_type ( lhs_ty ) ;
2809+ self . space ( ) ;
2810+ self . word_space ( "=" ) ;
2811+ self . print_type ( rhs_ty ) ;
28112812 }
28122813 }
28132814 }
@@ -2908,10 +2909,7 @@ impl<'a> State<'a> {
29082909 generic_params : & [ ast:: GenericParam ] ,
29092910 ) {
29102911 self . ibox ( INDENT_UNIT ) ;
2911- if !generic_params. is_empty ( ) {
2912- self . word ( "for" ) ;
2913- self . print_generic_params ( generic_params) ;
2914- }
2912+ self . print_formal_generic_params ( generic_params) ;
29152913 let generics = ast:: Generics {
29162914 params : Vec :: new ( ) ,
29172915 where_clause : ast:: WhereClause {
0 commit comments