@@ -498,16 +498,9 @@ pub trait PrettyPrinter<'tcx>:
498498 }
499499 ty:: Never => p ! ( write( "!" ) ) ,
500500 ty:: Tuple ( ref tys) => {
501- p ! ( write( "(" ) ) ;
502- let mut tys = tys. iter ( ) ;
503- if let Some ( & ty) = tys. next ( ) {
504- p ! ( print( ty) , write( "," ) ) ;
505- if let Some ( & ty) = tys. next ( ) {
506- p ! ( write( " " ) , print( ty) ) ;
507- for & ty in tys {
508- p ! ( write( ", " ) , print( ty) ) ;
509- }
510- }
501+ p ! ( write( "(" ) , comma_sep( tys. iter( ) . copied( ) ) ) ;
502+ if tys. len ( ) == 1 {
503+ p ! ( write( "," ) ) ;
511504 }
512505 p ! ( write( ")" ) )
513506 }
@@ -570,15 +563,10 @@ pub trait PrettyPrinter<'tcx>:
570563 let def_key = self . tcx ( ) . def_key ( def_id) ;
571564 if let Some ( name) = def_key. disambiguated_data . data . get_opt_name ( ) {
572565 p ! ( write( "{}" , name) ) ;
573- let mut substs = substs. iter ( ) ;
574566 // FIXME(eddyb) print this with `print_def_path`.
575- if let Some ( first) = substs. next ( ) {
576- p ! ( write( "::<" ) ) ;
577- p ! ( print( first) ) ;
578- for subst in substs {
579- p ! ( write( ", " ) , print( subst) ) ;
580- }
581- p ! ( write( ">" ) ) ;
567+ if !substs. is_empty ( ) {
568+ p ! ( write( "::" ) ) ;
569+ p ! ( generic_delimiters( |cx| cx. comma_sep( substs. iter( ) . copied( ) ) ) ) ;
582570 }
583571 return Ok ( self ) ;
584572 }
@@ -854,16 +842,12 @@ pub trait PrettyPrinter<'tcx>:
854842 ) -> Result < Self , Self :: Error > {
855843 define_scoped_cx ! ( self ) ;
856844
857- p ! ( write( "(" ) ) ;
858- let mut inputs = inputs. iter ( ) ;
859- if let Some ( & ty) = inputs. next ( ) {
860- p ! ( print( ty) ) ;
861- for & ty in inputs {
862- p ! ( write( ", " ) , print( ty) ) ;
863- }
864- if c_variadic {
865- p ! ( write( ", ..." ) ) ;
845+ p ! ( write( "(" ) , comma_sep( inputs. iter( ) . copied( ) ) ) ;
846+ if c_variadic {
847+ if !inputs. is_empty ( ) {
848+ p ! ( write( ", " ) ) ;
866849 }
850+ p ! ( write( "..." ) ) ;
867851 }
868852 p ! ( write( ")" ) ) ;
869853 if !output. is_unit ( ) {
@@ -1913,15 +1897,7 @@ define_print_and_forward_display! {
19131897 ( self , cx) :
19141898
19151899 & ' tcx ty:: List <Ty <' tcx>> {
1916- p!( write( "{{" ) ) ;
1917- let mut tys = self . iter( ) ;
1918- if let Some ( & ty) = tys. next( ) {
1919- p!( print( ty) ) ;
1920- for & ty in tys {
1921- p!( write( ", " ) , print( ty) ) ;
1922- }
1923- }
1924- p!( write( "}}" ) )
1900+ p!( write( "{{" ) , comma_sep( self . iter( ) . copied( ) ) , write( "}}" ) )
19251901 }
19261902
19271903 ty:: TypeAndMut <' tcx> {
0 commit comments