@@ -482,24 +482,26 @@ fn item_function(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, f: &clean::
482
482
+ name. as_str ( ) . len ( )
483
483
+ generics_len;
484
484
485
- wrap_item ( w, "fn" , |w| {
486
- render_attributes_in_pre ( w, it, "" ) ;
487
- w. reserve ( header_len) ;
488
- write ! (
489
- w,
490
- "{vis}{constness}{asyncness}{unsafety}{abi}fn \
491
- {name}{generics}{decl}{notable_traits}{where_clause}",
492
- vis = vis,
493
- constness = constness,
494
- asyncness = asyncness,
495
- unsafety = unsafety,
496
- abi = abi,
497
- name = name,
498
- generics = f. generics. print( cx) ,
499
- where_clause = print_where_clause( & f. generics, cx, 0 , true ) ,
500
- decl = f. decl. full_print( header_len, 0 , f. header. asyncness, cx) ,
501
- notable_traits = notable_traits_decl( & f. decl, cx) ,
502
- ) ;
485
+ wrap_into_docblock ( w, |w| {
486
+ wrap_item ( w, "fn" , |w| {
487
+ render_attributes_in_pre ( w, it, "" ) ;
488
+ w. reserve ( header_len) ;
489
+ write ! (
490
+ w,
491
+ "{vis}{constness}{asyncness}{unsafety}{abi}fn \
492
+ {name}{generics}{decl}{notable_traits}{where_clause}",
493
+ vis = vis,
494
+ constness = constness,
495
+ asyncness = asyncness,
496
+ unsafety = unsafety,
497
+ abi = abi,
498
+ name = name,
499
+ generics = f. generics. print( cx) ,
500
+ where_clause = print_where_clause( & f. generics, cx, 0 , true ) ,
501
+ decl = f. decl. full_print( header_len, 0 , f. header. asyncness, cx) ,
502
+ notable_traits = notable_traits_decl( & f. decl, cx) ,
503
+ ) ;
504
+ } ) ;
503
505
} ) ;
504
506
document ( w, cx, it, None , HeadingOffset :: H2 )
505
507
}
@@ -844,16 +846,18 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
844
846
}
845
847
846
848
fn item_trait_alias ( w : & mut Buffer , cx : & Context < ' _ > , it : & clean:: Item , t : & clean:: TraitAlias ) {
847
- wrap_item ( w, "trait-alias" , |w| {
848
- render_attributes_in_pre ( w, it, "" ) ;
849
- write ! (
850
- w,
851
- "trait {}{}{} = {};" ,
852
- it. name. as_ref( ) . unwrap( ) ,
853
- t. generics. print( cx) ,
854
- print_where_clause( & t. generics, cx, 0 , true ) ,
855
- bounds( & t. bounds, true , cx)
856
- ) ;
849
+ wrap_into_docblock ( w, |w| {
850
+ wrap_item ( w, "trait-alias" , |w| {
851
+ render_attributes_in_pre ( w, it, "" ) ;
852
+ write ! (
853
+ w,
854
+ "trait {}{}{} = {};" ,
855
+ it. name. as_ref( ) . unwrap( ) ,
856
+ t. generics. print( cx) ,
857
+ print_where_clause( & t. generics, cx, 0 , true ) ,
858
+ bounds( & t. bounds, true , cx)
859
+ ) ;
860
+ } ) ;
857
861
} ) ;
858
862
859
863
document ( w, cx, it, None , HeadingOffset :: H2 ) ;
@@ -866,16 +870,18 @@ fn item_trait_alias(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clea
866
870
}
867
871
868
872
fn item_opaque_ty ( w : & mut Buffer , cx : & Context < ' _ > , it : & clean:: Item , t : & clean:: OpaqueTy ) {
869
- wrap_item ( w, "opaque" , |w| {
870
- render_attributes_in_pre ( w, it, "" ) ;
871
- write ! (
872
- w,
873
- "type {}{}{where_clause} = impl {bounds};" ,
874
- it. name. as_ref( ) . unwrap( ) ,
875
- t. generics. print( cx) ,
876
- where_clause = print_where_clause( & t. generics, cx, 0 , true ) ,
877
- bounds = bounds( & t. bounds, false , cx) ,
878
- ) ;
873
+ wrap_into_docblock ( w, |w| {
874
+ wrap_item ( w, "opaque" , |w| {
875
+ render_attributes_in_pre ( w, it, "" ) ;
876
+ write ! (
877
+ w,
878
+ "type {}{}{where_clause} = impl {bounds};" ,
879
+ it. name. as_ref( ) . unwrap( ) ,
880
+ t. generics. print( cx) ,
881
+ where_clause = print_where_clause( & t. generics, cx, 0 , true ) ,
882
+ bounds = bounds( & t. bounds, false , cx) ,
883
+ ) ;
884
+ } ) ;
879
885
} ) ;
880
886
881
887
document ( w, cx, it, None , HeadingOffset :: H2 ) ;
@@ -894,20 +900,37 @@ fn item_typedef(
894
900
t : & clean:: Typedef ,
895
901
is_associated : bool ,
896
902
) {
897
- wrap_item ( w, "typedef" , |w| {
898
- render_attributes_in_pre ( w, it, "" ) ;
899
- if !is_associated {
900
- write ! ( w, "{}" , it. visibility. print_with_space( it. def_id, cx) ) ;
901
- }
902
- write ! (
903
- w,
904
- "type {}{}{where_clause} = {type_};" ,
905
- it. name. as_ref( ) . unwrap( ) ,
906
- t. generics. print( cx) ,
907
- where_clause = print_where_clause( & t. generics, cx, 0 , true ) ,
908
- type_ = t. type_. print( cx) ,
909
- ) ;
910
- } ) ;
903
+ fn write_content (
904
+ w : & mut Buffer ,
905
+ cx : & Context < ' _ > ,
906
+ it : & clean:: Item ,
907
+ t : & clean:: Typedef ,
908
+ is_associated : bool ,
909
+ ) {
910
+ wrap_item ( w, "typedef" , |w| {
911
+ render_attributes_in_pre ( w, it, "" ) ;
912
+ if !is_associated {
913
+ write ! ( w, "{}" , it. visibility. print_with_space( it. def_id, cx) ) ;
914
+ }
915
+ write ! (
916
+ w,
917
+ "type {}{}{where_clause} = {type_};" ,
918
+ it. name. as_ref( ) . unwrap( ) ,
919
+ t. generics. print( cx) ,
920
+ where_clause = print_where_clause( & t. generics, cx, 0 , true ) ,
921
+ type_ = t. type_. print( cx) ,
922
+ ) ;
923
+ } ) ;
924
+ }
925
+
926
+ // If this is an associated typedef, we don't want to wrap it into a docblock.
927
+ if is_associated {
928
+ write_content ( w, cx, it, t, is_associated) ;
929
+ } else {
930
+ wrap_into_docblock ( w, |w| {
931
+ write_content ( w, cx, it, t, is_associated) ;
932
+ } ) ;
933
+ }
911
934
912
935
document ( w, cx, it, None , HeadingOffset :: H2 ) ;
913
936
@@ -1142,32 +1165,34 @@ fn item_macro(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Mac
1142
1165
}
1143
1166
1144
1167
fn item_proc_macro ( w : & mut Buffer , cx : & Context < ' _ > , it : & clean:: Item , m : & clean:: ProcMacro ) {
1145
- let name = it. name . as_ref ( ) . expect ( "proc-macros always have names" ) ;
1146
- match m. kind {
1147
- MacroKind :: Bang => {
1148
- wrap_item ( w, "macro" , |w| {
1149
- write ! ( w, "{}!() {{ /* proc-macro */ }}" , name) ;
1150
- } ) ;
1151
- }
1152
- MacroKind :: Attr => {
1153
- wrap_item ( w, "attr" , |w| {
1154
- write ! ( w, "#[{}]" , name) ;
1155
- } ) ;
1156
- }
1157
- MacroKind :: Derive => {
1158
- wrap_item ( w, "derive" , |w| {
1159
- write ! ( w, "#[derive({})]" , name) ;
1160
- if !m. helpers . is_empty ( ) {
1161
- w. push_str ( "\n {\n " ) ;
1162
- w. push_str ( " // Attributes available to this derive:\n " ) ;
1163
- for attr in & m. helpers {
1164
- writeln ! ( w, " #[{}]" , attr) ;
1168
+ wrap_into_docblock ( w, |w| {
1169
+ let name = it. name . as_ref ( ) . expect ( "proc-macros always have names" ) ;
1170
+ match m. kind {
1171
+ MacroKind :: Bang => {
1172
+ wrap_item ( w, "macro" , |w| {
1173
+ write ! ( w, "{}!() {{ /* proc-macro */ }}" , name) ;
1174
+ } ) ;
1175
+ }
1176
+ MacroKind :: Attr => {
1177
+ wrap_item ( w, "attr" , |w| {
1178
+ write ! ( w, "#[{}]" , name) ;
1179
+ } ) ;
1180
+ }
1181
+ MacroKind :: Derive => {
1182
+ wrap_item ( w, "derive" , |w| {
1183
+ write ! ( w, "#[derive({})]" , name) ;
1184
+ if !m. helpers . is_empty ( ) {
1185
+ w. push_str ( "\n {\n " ) ;
1186
+ w. push_str ( " // Attributes available to this derive:\n " ) ;
1187
+ for attr in & m. helpers {
1188
+ writeln ! ( w, " #[{}]" , attr) ;
1189
+ }
1190
+ w. push_str ( "}\n " ) ;
1165
1191
}
1166
- w. push_str ( "}\n " ) ;
1167
- }
1168
- } ) ;
1192
+ } ) ;
1193
+ }
1169
1194
}
1170
- }
1195
+ } ) ;
1171
1196
document ( w, cx, it, None , HeadingOffset :: H2 )
1172
1197
}
1173
1198
@@ -1177,38 +1202,40 @@ fn item_primitive(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item) {
1177
1202
}
1178
1203
1179
1204
fn item_constant ( w : & mut Buffer , cx : & Context < ' _ > , it : & clean:: Item , c : & clean:: Constant ) {
1180
- wrap_item ( w, "const" , |w| {
1181
- render_attributes_in_code ( w, it) ;
1205
+ wrap_into_docblock ( w, |w| {
1206
+ wrap_item ( w, "const" , |w| {
1207
+ render_attributes_in_code ( w, it) ;
1182
1208
1183
- write ! (
1184
- w,
1185
- "{vis}const {name}: {typ}" ,
1186
- vis = it. visibility. print_with_space( it. def_id, cx) ,
1187
- name = it. name. as_ref( ) . unwrap( ) ,
1188
- typ = c. type_. print( cx) ,
1189
- ) ;
1209
+ write ! (
1210
+ w,
1211
+ "{vis}const {name}: {typ}" ,
1212
+ vis = it. visibility. print_with_space( it. def_id, cx) ,
1213
+ name = it. name. as_ref( ) . unwrap( ) ,
1214
+ typ = c. type_. print( cx) ,
1215
+ ) ;
1190
1216
1191
- let value = c. value ( cx. tcx ( ) ) ;
1192
- let is_literal = c. is_literal ( cx. tcx ( ) ) ;
1193
- let expr = c. expr ( cx. tcx ( ) ) ;
1194
- if value. is_some ( ) || is_literal {
1195
- write ! ( w, " = {expr};" , expr = Escape ( & expr) ) ;
1196
- } else {
1197
- w. write_str ( ";" ) ;
1198
- }
1217
+ let value = c. value ( cx. tcx ( ) ) ;
1218
+ let is_literal = c. is_literal ( cx. tcx ( ) ) ;
1219
+ let expr = c. expr ( cx. tcx ( ) ) ;
1220
+ if value. is_some ( ) || is_literal {
1221
+ write ! ( w, " = {expr};" , expr = Escape ( & expr) ) ;
1222
+ } else {
1223
+ w. write_str ( ";" ) ;
1224
+ }
1199
1225
1200
- if !is_literal {
1201
- if let Some ( value) = & value {
1202
- let value_lowercase = value. to_lowercase ( ) ;
1203
- let expr_lowercase = expr. to_lowercase ( ) ;
1226
+ if !is_literal {
1227
+ if let Some ( value) = & value {
1228
+ let value_lowercase = value. to_lowercase ( ) ;
1229
+ let expr_lowercase = expr. to_lowercase ( ) ;
1204
1230
1205
- if value_lowercase != expr_lowercase
1206
- && value_lowercase. trim_end_matches ( "i32" ) != expr_lowercase
1207
- {
1208
- write ! ( w, " // {value}" , value = Escape ( value) ) ;
1231
+ if value_lowercase != expr_lowercase
1232
+ && value_lowercase. trim_end_matches ( "i32" ) != expr_lowercase
1233
+ {
1234
+ write ! ( w, " // {value}" , value = Escape ( value) ) ;
1235
+ }
1209
1236
}
1210
1237
}
1211
- }
1238
+ } ) ;
1212
1239
} ) ;
1213
1240
1214
1241
document ( w, cx, it, None , HeadingOffset :: H2 )
@@ -1268,30 +1295,34 @@ fn item_struct(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::St
1268
1295
}
1269
1296
1270
1297
fn item_static ( w : & mut Buffer , cx : & Context < ' _ > , it : & clean:: Item , s : & clean:: Static ) {
1271
- wrap_item ( w, "static" , |w| {
1272
- render_attributes_in_code ( w, it) ;
1273
- write ! (
1274
- w,
1275
- "{vis}static {mutability}{name}: {typ}" ,
1276
- vis = it. visibility. print_with_space( it. def_id, cx) ,
1277
- mutability = s. mutability. print_with_space( ) ,
1278
- name = it. name. as_ref( ) . unwrap( ) ,
1279
- typ = s. type_. print( cx)
1280
- ) ;
1298
+ wrap_into_docblock ( w, |w| {
1299
+ wrap_item ( w, "static" , |w| {
1300
+ render_attributes_in_code ( w, it) ;
1301
+ write ! (
1302
+ w,
1303
+ "{vis}static {mutability}{name}: {typ}" ,
1304
+ vis = it. visibility. print_with_space( it. def_id, cx) ,
1305
+ mutability = s. mutability. print_with_space( ) ,
1306
+ name = it. name. as_ref( ) . unwrap( ) ,
1307
+ typ = s. type_. print( cx)
1308
+ ) ;
1309
+ } ) ;
1281
1310
} ) ;
1282
1311
document ( w, cx, it, None , HeadingOffset :: H2 )
1283
1312
}
1284
1313
1285
1314
fn item_foreign_type ( w : & mut Buffer , cx : & Context < ' _ > , it : & clean:: Item ) {
1286
- wrap_item ( w, "foreigntype" , |w| {
1287
- w. write_str ( "extern {\n " ) ;
1288
- render_attributes_in_code ( w, it) ;
1289
- write ! (
1290
- w,
1291
- " {}type {};\n }}" ,
1292
- it. visibility. print_with_space( it. def_id, cx) ,
1293
- it. name. as_ref( ) . unwrap( ) ,
1294
- ) ;
1315
+ wrap_into_docblock ( w, |w| {
1316
+ wrap_item ( w, "foreigntype" , |w| {
1317
+ w. write_str ( "extern {\n " ) ;
1318
+ render_attributes_in_code ( w, it) ;
1319
+ write ! (
1320
+ w,
1321
+ " {}type {};\n }}" ,
1322
+ it. visibility. print_with_space( it. def_id, cx) ,
1323
+ it. name. as_ref( ) . unwrap( ) ,
1324
+ ) ;
1325
+ } ) ;
1295
1326
} ) ;
1296
1327
1297
1328
document ( w, cx, it, None , HeadingOffset :: H2 ) ;
@@ -1374,7 +1405,7 @@ fn wrap_into_docblock<F>(w: &mut Buffer, f: F)
1374
1405
where
1375
1406
F : FnOnce ( & mut Buffer ) ,
1376
1407
{
1377
- w. write_str ( "<div class=\" docblock type -decl\" >" ) ;
1408
+ w. write_str ( "<div class=\" docblock item -decl\" >" ) ;
1378
1409
f ( w) ;
1379
1410
w. write_str ( "</div>" )
1380
1411
}
0 commit comments