@@ -814,7 +814,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
814814 }
815815
816816 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) )
818818 }
819819
820820 fn pat_to_string ( & self , pat : & ast:: Pat ) -> String {
@@ -991,7 +991,12 @@ impl<'a> State<'a> {
991991 Term :: Const ( c) => self . print_expr_anon_const ( c, & [ ] ) ,
992992 }
993993 }
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+ }
9951000 }
9961001 }
9971002
@@ -1045,11 +1050,14 @@ impl<'a> State<'a> {
10451050 }
10461051 ast:: TyKind :: Path ( Some ( ref qself) , ref path) => self . print_qpath ( path, qself, false ) ,
10471052 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) ;
10501057 }
10511058 ast:: TyKind :: ImplTrait ( _, ref bounds) => {
1052- self . print_type_bounds ( "impl" , & bounds) ;
1059+ self . word_nbsp ( "impl" ) ;
1060+ self . print_type_bounds ( bounds) ;
10531061 }
10541062 ast:: TyKind :: Array ( ref ty, ref length) => {
10551063 self . word ( "[" ) ;
@@ -1549,29 +1557,24 @@ impl<'a> State<'a> {
15491557 }
15501558 }
15511559
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+ }
15651569
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 ( "?" ) ;
15721574 }
1573- GenericBound :: Outlives ( lt ) => self . print_lifetime ( * lt ) ,
1575+ self . print_poly_trait_ref ( tref ) ;
15741576 }
1577+ GenericBound :: Outlives ( lt) => self . print_lifetime ( * lt) ,
15751578 }
15761579 }
15771580 }
@@ -1580,22 +1583,14 @@ impl<'a> State<'a> {
15801583 self . print_name ( lifetime. ident . name )
15811584 }
15821585
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 ! ( ) ,
15991594 }
16001595 }
16011596 }
@@ -1613,11 +1608,18 @@ impl<'a> State<'a> {
16131608 match param. kind {
16141609 ast:: GenericParamKind :: Lifetime => {
16151610 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+ }
16171616 }
16181617 ast:: GenericParamKind :: Type { ref default } => {
16191618 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+ }
16211623 if let Some ( ref default) = default {
16221624 s. space ( ) ;
16231625 s. word_space ( "=" ) ;
@@ -1630,7 +1632,10 @@ impl<'a> State<'a> {
16301632 s. space ( ) ;
16311633 s. word_space ( ":" ) ;
16321634 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+ }
16341639 if let Some ( ref default) = default {
16351640 s. space ( ) ;
16361641 s. word_space ( "=" ) ;
0 commit comments