@@ -498,16 +498,9 @@ pub trait PrettyPrinter<'tcx>:
498
498
}
499
499
ty:: Never => p ! ( write( "!" ) ) ,
500
500
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( "," ) ) ;
511
504
}
512
505
p ! ( write( ")" ) )
513
506
}
@@ -570,15 +563,10 @@ pub trait PrettyPrinter<'tcx>:
570
563
let def_key = self . tcx ( ) . def_key ( def_id) ;
571
564
if let Some ( name) = def_key. disambiguated_data . data . get_opt_name ( ) {
572
565
p ! ( write( "{}" , name) ) ;
573
- let mut substs = substs. iter ( ) ;
574
566
// 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( ) ) ) ) ;
582
570
}
583
571
return Ok ( self ) ;
584
572
}
@@ -854,16 +842,12 @@ pub trait PrettyPrinter<'tcx>:
854
842
) -> Result < Self , Self :: Error > {
855
843
define_scoped_cx ! ( self ) ;
856
844
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( ", " ) ) ;
866
849
}
850
+ p ! ( write( "..." ) ) ;
867
851
}
868
852
p ! ( write( ")" ) ) ;
869
853
if !output. is_unit ( ) {
@@ -1913,15 +1897,7 @@ define_print_and_forward_display! {
1913
1897
( self , cx) :
1914
1898
1915
1899
& ' 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( "}}" ) )
1925
1901
}
1926
1902
1927
1903
ty:: TypeAndMut <' tcx> {
0 commit comments