@@ -814,7 +814,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
814
814
}
815
815
816
816
fn bounds_to_string ( & self , bounds : & [ ast:: GenericBound ] ) -> String {
817
- Self :: to_string ( |s| s. print_type_bounds ( "" , bounds) )
817
+ Self :: to_string ( |s| s. print_type_bounds ( bounds) )
818
818
}
819
819
820
820
fn pat_to_string ( & self , pat : & ast:: Pat ) -> String {
@@ -991,7 +991,12 @@ impl<'a> State<'a> {
991
991
Term :: Const ( c) => self . print_expr_anon_const ( c, & [ ] ) ,
992
992
}
993
993
}
994
- ast:: AssocConstraintKind :: Bound { bounds } => self . print_type_bounds ( ":" , & * bounds) ,
994
+ ast:: AssocConstraintKind :: Bound { bounds } => {
995
+ if !bounds. is_empty ( ) {
996
+ self . word_nbsp ( ":" ) ;
997
+ self . print_type_bounds ( & bounds) ;
998
+ }
999
+ }
995
1000
}
996
1001
}
997
1002
@@ -1045,11 +1050,14 @@ impl<'a> State<'a> {
1045
1050
}
1046
1051
ast:: TyKind :: Path ( Some ( ref qself) , ref path) => self . print_qpath ( path, qself, false ) ,
1047
1052
ast:: TyKind :: TraitObject ( ref bounds, syntax) => {
1048
- let prefix = if syntax == ast:: TraitObjectSyntax :: Dyn { "dyn" } else { "" } ;
1049
- self . print_type_bounds ( prefix, & bounds) ;
1053
+ if syntax == ast:: TraitObjectSyntax :: Dyn {
1054
+ self . word_nbsp ( "dyn" ) ;
1055
+ }
1056
+ self . print_type_bounds ( bounds) ;
1050
1057
}
1051
1058
ast:: TyKind :: ImplTrait ( _, ref bounds) => {
1052
- self . print_type_bounds ( "impl" , & bounds) ;
1059
+ self . word_nbsp ( "impl" ) ;
1060
+ self . print_type_bounds ( bounds) ;
1053
1061
}
1054
1062
ast:: TyKind :: Array ( ref ty, ref length) => {
1055
1063
self . word ( "[" ) ;
@@ -1549,29 +1557,24 @@ impl<'a> State<'a> {
1549
1557
}
1550
1558
}
1551
1559
1552
- pub fn print_type_bounds ( & mut self , prefix : & ' static str , bounds : & [ ast:: GenericBound ] ) {
1553
- if !bounds. is_empty ( ) {
1554
- self . word ( prefix) ;
1555
- let mut first = true ;
1556
- for bound in bounds {
1557
- if !( first && prefix. is_empty ( ) ) {
1558
- self . nbsp ( ) ;
1559
- }
1560
- if first {
1561
- first = false ;
1562
- } else {
1563
- self . word_space ( "+" ) ;
1564
- }
1560
+ pub fn print_type_bounds ( & mut self , bounds : & [ ast:: GenericBound ] ) {
1561
+ let mut first = true ;
1562
+ for bound in bounds {
1563
+ if first {
1564
+ first = false ;
1565
+ } else {
1566
+ self . nbsp ( ) ;
1567
+ self . word_space ( "+" ) ;
1568
+ }
1565
1569
1566
- match bound {
1567
- GenericBound :: Trait ( tref, modifier) => {
1568
- if modifier == & TraitBoundModifier :: Maybe {
1569
- self . word ( "?" ) ;
1570
- }
1571
- self . print_poly_trait_ref ( tref) ;
1570
+ match bound {
1571
+ GenericBound :: Trait ( tref, modifier) => {
1572
+ if modifier == & TraitBoundModifier :: Maybe {
1573
+ self . word ( "?" ) ;
1572
1574
}
1573
- GenericBound :: Outlives ( lt ) => self . print_lifetime ( * lt ) ,
1575
+ self . print_poly_trait_ref ( tref ) ;
1574
1576
}
1577
+ GenericBound :: Outlives ( lt) => self . print_lifetime ( * lt) ,
1575
1578
}
1576
1579
}
1577
1580
}
@@ -1580,22 +1583,14 @@ impl<'a> State<'a> {
1580
1583
self . print_name ( lifetime. ident . name )
1581
1584
}
1582
1585
1583
- pub ( crate ) fn print_lifetime_bounds (
1584
- & mut self ,
1585
- lifetime : ast:: Lifetime ,
1586
- bounds : & ast:: GenericBounds ,
1587
- ) {
1588
- self . print_lifetime ( lifetime) ;
1589
- if !bounds. is_empty ( ) {
1590
- self . word ( ": " ) ;
1591
- for ( i, bound) in bounds. iter ( ) . enumerate ( ) {
1592
- if i != 0 {
1593
- self . word ( " + " ) ;
1594
- }
1595
- match bound {
1596
- ast:: GenericBound :: Outlives ( lt) => self . print_lifetime ( * lt) ,
1597
- _ => panic ! ( ) ,
1598
- }
1586
+ pub ( crate ) fn print_lifetime_bounds ( & mut self , bounds : & ast:: GenericBounds ) {
1587
+ for ( i, bound) in bounds. iter ( ) . enumerate ( ) {
1588
+ if i != 0 {
1589
+ self . word ( " + " ) ;
1590
+ }
1591
+ match bound {
1592
+ ast:: GenericBound :: Outlives ( lt) => self . print_lifetime ( * lt) ,
1593
+ _ => panic ! ( ) ,
1599
1594
}
1600
1595
}
1601
1596
}
@@ -1613,11 +1608,18 @@ impl<'a> State<'a> {
1613
1608
match param. kind {
1614
1609
ast:: GenericParamKind :: Lifetime => {
1615
1610
let lt = ast:: Lifetime { id : param. id , ident : param. ident } ;
1616
- s. print_lifetime_bounds ( lt, & param. bounds )
1611
+ s. print_lifetime ( lt) ;
1612
+ if !param. bounds . is_empty ( ) {
1613
+ s. word_nbsp ( ":" ) ;
1614
+ s. print_lifetime_bounds ( & param. bounds )
1615
+ }
1617
1616
}
1618
1617
ast:: GenericParamKind :: Type { ref default } => {
1619
1618
s. print_ident ( param. ident ) ;
1620
- s. print_type_bounds ( ":" , & param. bounds ) ;
1619
+ if !param. bounds . is_empty ( ) {
1620
+ s. word_nbsp ( ":" ) ;
1621
+ s. print_type_bounds ( & param. bounds ) ;
1622
+ }
1621
1623
if let Some ( ref default) = default {
1622
1624
s. space ( ) ;
1623
1625
s. word_space ( "=" ) ;
@@ -1630,7 +1632,10 @@ impl<'a> State<'a> {
1630
1632
s. space ( ) ;
1631
1633
s. word_space ( ":" ) ;
1632
1634
s. print_type ( ty) ;
1633
- s. print_type_bounds ( ":" , & param. bounds ) ;
1635
+ if !param. bounds . is_empty ( ) {
1636
+ s. word_nbsp ( ":" ) ;
1637
+ s. print_type_bounds ( & param. bounds ) ;
1638
+ }
1634
1639
if let Some ( ref default) = default {
1635
1640
s. space ( ) ;
1636
1641
s. word_space ( "=" ) ;
0 commit comments