@@ -23,6 +23,8 @@ use rustc_span::symbol::kw;
23
23
use rustc_span:: { sym, Symbol } ;
24
24
use rustc_target:: spec:: abi:: Abi ;
25
25
26
+ use itertools:: Itertools ;
27
+
26
28
use crate :: clean:: {
27
29
self , types:: ExternalLocation , utils:: find_nearest_parent_module, ExternalCrate , ItemId ,
28
30
PrimitiveType ,
@@ -874,20 +876,42 @@ fn fmt_type<'cx>(
874
876
match & typs[ ..] {
875
877
& [ ] => primitive_link ( f, PrimitiveType :: Unit , "()" , cx) ,
876
878
& [ 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
+ }
881
887
}
882
888
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) ?;
887
912
}
888
- fmt :: Display :: fmt ( & item . print ( cx ) , f ) ? ;
913
+ write ! ( f , ")" )
889
914
}
890
- primitive_link ( f, PrimitiveType :: Tuple , ")" , cx)
891
915
}
892
916
}
893
917
}
0 commit comments