@@ -23,6 +23,8 @@ use rustc_span::symbol::kw;
2323use rustc_span:: { sym, Symbol } ;
2424use rustc_target:: spec:: abi:: Abi ;
2525
26+ use itertools:: Itertools ;
27+
2628use crate :: clean:: {
2729 self , types:: ExternalLocation , utils:: find_nearest_parent_module, ExternalCrate , ItemId ,
2830 PrimitiveType ,
@@ -874,20 +876,42 @@ fn fmt_type<'cx>(
874876 match & typs[ ..] {
875877 & [ ] => primitive_link ( f, PrimitiveType :: Unit , "()" , cx) ,
876878 & [ ref one] => {
877- primitive_link ( f, PrimitiveType :: Tuple , "(" , cx) ?;
878- // Carry `f.alternate()` into this display w/o branching manually.
879- fmt:: Display :: fmt ( & one. print ( cx) , f) ?;
880- primitive_link ( f, PrimitiveType :: Tuple , ",)" , cx)
879+ if let clean:: Generic ( name) = one {
880+ primitive_link ( f, PrimitiveType :: Tuple , & format ! ( "({name},)" ) , cx)
881+ } else {
882+ write ! ( f, "(" ) ?;
883+ // Carry `f.alternate()` into this display w/o branching manually.
884+ fmt:: Display :: fmt ( & one. print ( cx) , f) ?;
885+ write ! ( f, ",)" )
886+ }
881887 }
882888 many => {
883- primitive_link ( f, PrimitiveType :: Tuple , "(" , cx) ?;
884- for ( i, item) in many. iter ( ) . enumerate ( ) {
885- if i != 0 {
886- write ! ( f, ", " ) ?;
889+ let generic_names: Vec < Symbol > = many
890+ . iter ( )
891+ . filter_map ( |t| match t {
892+ clean:: Generic ( name) => Some ( * name) ,
893+ _ => None ,
894+ } )
895+ . collect ( ) ;
896+ let is_generic = generic_names. len ( ) == many. len ( ) ;
897+ if is_generic {
898+ primitive_link (
899+ f,
900+ PrimitiveType :: Tuple ,
901+ & format ! ( "({})" , generic_names. iter( ) . map( |s| s. as_str( ) ) . join( ", " ) ) ,
902+ cx,
903+ )
904+ } else {
905+ write ! ( f, "(" ) ?;
906+ for ( i, item) in many. iter ( ) . enumerate ( ) {
907+ if i != 0 {
908+ write ! ( f, ", " ) ?;
909+ }
910+ // Carry `f.alternate()` into this display w/o branching manually.
911+ fmt:: Display :: fmt ( & item. print ( cx) , f) ?;
887912 }
888- fmt :: Display :: fmt ( & item . print ( cx ) , f ) ? ;
913+ write ! ( f , ")" )
889914 }
890- primitive_link ( f, PrimitiveType :: Tuple , ")" , cx)
891915 }
892916 }
893917 }
0 commit comments