@@ -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
}
@@ -2780,34 +2781,34 @@ impl<'a> State<'a> {
2780
2781
self . word_space ( "," ) ;
2781
2782
}
2782
2783
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 ) ;
2811
2812
}
2812
2813
}
2813
2814
}
@@ -2908,10 +2909,7 @@ impl<'a> State<'a> {
2908
2909
generic_params : & [ ast:: GenericParam ] ,
2909
2910
) {
2910
2911
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) ;
2915
2913
let generics = ast:: Generics {
2916
2914
params : Vec :: new ( ) ,
2917
2915
where_clause : ast:: WhereClause {
0 commit comments