@@ -958,6 +958,24 @@ pub(crate) fn anchor<'a, 'cx: 'a>(
958
958
} )
959
959
}
960
960
961
+ fn fmt_slice < ' cx > (
962
+ f : & mut fmt:: Formatter < ' _ > ,
963
+ t : & clean:: Type ,
964
+ extra : & str ,
965
+ cx : & ' cx Context < ' _ > ,
966
+ ) -> fmt:: Result {
967
+ match * t {
968
+ clean:: Generic ( name) => {
969
+ primitive_link ( f, PrimitiveType :: Slice , & format ! ( "{extra}[{name}]" ) , cx)
970
+ }
971
+ _ => {
972
+ write ! ( f, "{extra}[" ) ?;
973
+ fmt:: Display :: fmt ( & t. print ( cx) , f) ?;
974
+ f. write_str ( "]" )
975
+ }
976
+ }
977
+ }
978
+
961
979
fn fmt_type < ' cx > (
962
980
t : & clean:: Type ,
963
981
f : & mut fmt:: Formatter < ' _ > ,
@@ -1008,55 +1026,25 @@ fn fmt_type<'cx>(
1008
1026
match & typs[ ..] {
1009
1027
& [ ] => primitive_link ( f, PrimitiveType :: Unit , "()" , cx) ,
1010
1028
[ one] => {
1011
- if let clean:: Generic ( name) = one {
1012
- primitive_link ( f, PrimitiveType :: Tuple , & format ! ( "({name},)" ) , cx)
1013
- } else {
1014
- write ! ( f, "(" ) ?;
1015
- // Carry `f.alternate()` into this display w/o branching manually.
1016
- fmt:: Display :: fmt ( & one. print ( cx) , f) ?;
1017
- write ! ( f, ",)" )
1018
- }
1029
+ write ! ( f, "(" ) ?;
1030
+ // Carry `f.alternate()` into this display w/o branching manually.
1031
+ fmt:: Display :: fmt ( & one. print ( cx) , f) ?;
1032
+ write ! ( f, ",)" )
1019
1033
}
1020
1034
many => {
1021
- let generic_names: Vec < Symbol > = many
1022
- . iter ( )
1023
- . filter_map ( |t| match t {
1024
- clean:: Generic ( name) => Some ( * name) ,
1025
- _ => None ,
1026
- } )
1027
- . collect ( ) ;
1028
- let is_generic = generic_names. len ( ) == many. len ( ) ;
1029
- if is_generic {
1030
- primitive_link (
1031
- f,
1032
- PrimitiveType :: Tuple ,
1033
- & format ! ( "({})" , generic_names. iter( ) . map( |s| s. as_str( ) ) . join( ", " ) ) ,
1034
- cx,
1035
- )
1036
- } else {
1037
- write ! ( f, "(" ) ?;
1038
- for ( i, item) in many. iter ( ) . enumerate ( ) {
1039
- if i != 0 {
1040
- write ! ( f, ", " ) ?;
1041
- }
1042
- // Carry `f.alternate()` into this display w/o branching manually.
1043
- fmt:: Display :: fmt ( & item. print ( cx) , f) ?;
1035
+ write ! ( f, "(" ) ?;
1036
+ for ( i, item) in many. iter ( ) . enumerate ( ) {
1037
+ if i != 0 {
1038
+ write ! ( f, ", " ) ?;
1044
1039
}
1045
- write ! ( f, ")" )
1040
+ // Carry `f.alternate()` into this display w/o branching manually.
1041
+ fmt:: Display :: fmt ( & item. print ( cx) , f) ?;
1046
1042
}
1043
+ write ! ( f, ")" )
1047
1044
}
1048
1045
}
1049
1046
}
1050
- clean:: Slice ( ref t) => match * * t {
1051
- clean:: Generic ( name) => {
1052
- primitive_link ( f, PrimitiveType :: Slice , & format ! ( "[{name}]" ) , cx)
1053
- }
1054
- _ => {
1055
- write ! ( f, "[" ) ?;
1056
- fmt:: Display :: fmt ( & t. print ( cx) , f) ?;
1057
- write ! ( f, "]" )
1058
- }
1059
- } ,
1047
+ clean:: Slice ( ref t) => fmt_slice ( f, & * * t, "" , cx) ,
1060
1048
clean:: Array ( ref t, ref n) => match * * t {
1061
1049
clean:: Generic ( name) if !f. alternate ( ) => primitive_link (
1062
1050
f,
@@ -1070,10 +1058,9 @@ fn fmt_type<'cx>(
1070
1058
if f. alternate ( ) {
1071
1059
write ! ( f, "; {n}" ) ?;
1072
1060
} else {
1073
- write ! ( f, "; " ) ?;
1074
- primitive_link ( f, PrimitiveType :: Array , & format ! ( "{n}" , n = Escape ( n) ) , cx) ?;
1061
+ write ! ( f, "; {}" , Escape ( n) ) ?;
1075
1062
}
1076
- write ! ( f , "]" )
1063
+ f . write_str ( "]" )
1077
1064
}
1078
1065
} ,
1079
1066
clean:: RawPointer ( m, ref t) => {
@@ -1082,36 +1069,34 @@ fn fmt_type<'cx>(
1082
1069
hir:: Mutability :: Not => "const" ,
1083
1070
} ;
1084
1071
1085
- if matches ! ( * * t, clean:: Generic ( _) ) || t. is_assoc_ty ( ) {
1086
- let text = if f. alternate ( ) {
1087
- format ! ( "*{m} {ty:#}" , ty = t. print( cx) )
1088
- } else {
1089
- format ! ( "*{m} {ty}" , ty = t. print( cx) )
1090
- } ;
1091
- primitive_link ( f, clean:: PrimitiveType :: RawPointer , & text, cx)
1092
- } else {
1093
- primitive_link ( f, clean:: PrimitiveType :: RawPointer , & format ! ( "*{m} " ) , cx) ?;
1094
- fmt:: Display :: fmt ( & t. print ( cx) , f)
1095
- }
1072
+ primitive_link ( f, clean:: PrimitiveType :: RawPointer , & format ! ( "*{m} " ) , cx) ?;
1073
+ fmt:: Display :: fmt ( & t. print ( cx) , f)
1096
1074
}
1097
1075
clean:: BorrowedRef { lifetime : ref l, mutability, type_ : ref ty } => {
1098
- let lt = match l {
1076
+ let lifetime = match l {
1099
1077
Some ( l) => format ! ( "{} " , l. print( ) ) ,
1100
1078
_ => String :: new ( ) ,
1101
1079
} ;
1102
1080
let m = mutability. print_with_space ( ) ;
1103
1081
let amp = if f. alternate ( ) { "&" } else { "&" } ;
1104
1082
1105
- if let clean:: Generic ( name) = * * ty {
1106
- return primitive_link (
1107
- f,
1108
- PrimitiveType :: Reference ,
1109
- & format ! ( "{amp}{lt}{m}{name}" ) ,
1110
- cx,
1111
- ) ;
1083
+ match * * ty {
1084
+ clean:: Generic ( name) => {
1085
+ primitive_link (
1086
+ f,
1087
+ PrimitiveType :: Reference ,
1088
+ & format ! ( "{amp}{lifetime}{m}" ) ,
1089
+ cx,
1090
+ ) ?;
1091
+ return write ! ( f, "{name}" ) ;
1092
+ }
1093
+ clean:: Slice ( ref t) => {
1094
+ return fmt_slice ( f, & * * t, & format ! ( "{amp}{lifetime}{m}" ) , cx) ;
1095
+ }
1096
+ _ => { }
1112
1097
}
1113
1098
1114
- write ! ( f, "{amp}{lt }{m}" ) ?;
1099
+ write ! ( f, "{amp}{lifetime }{m}" ) ?;
1115
1100
1116
1101
let needs_parens = match * * ty {
1117
1102
clean:: DynTrait ( ref bounds, ref trait_lt)
@@ -1192,7 +1177,7 @@ fn fmt_type<'cx>(
1192
1177
write ! (
1193
1178
f,
1194
1179
"<a class=\" associatedtype\" href=\" {url}#{shortty}.{name}\" \
1195
- title=\" type {path}::{name}\" >{name}</a>",
1180
+ title=\" type {path}::{name}\" >{name}</a>",
1196
1181
shortty = ItemType :: AssocType ,
1197
1182
name = assoc. name,
1198
1183
path = join_with_double_colon( & path) ,
0 commit comments