@@ -660,7 +660,7 @@ fn short_item_info(
660
660
// "Auto Trait Implementations," "Blanket Trait Implementations" (on struct/enum pages).
661
661
pub ( crate ) fn render_impls (
662
662
cx : & mut Context < ' _ > ,
663
- w : & mut Buffer ,
663
+ mut w : impl Write ,
664
664
impls : & [ & Impl ] ,
665
665
containing_item : & clean:: Item ,
666
666
toggle_open_by_default : bool ,
@@ -672,7 +672,7 @@ pub(crate) fn render_impls(
672
672
let did = i. trait_did ( ) . unwrap ( ) ;
673
673
let provided_trait_methods = i. inner_impl ( ) . provided_trait_methods ( tcx) ;
674
674
let assoc_link = AssocItemLink :: GotoSource ( did. into ( ) , & provided_trait_methods) ;
675
- let mut buffer = if w . is_for_html ( ) { Buffer :: html ( ) } else { Buffer :: new ( ) } ;
675
+ let mut buffer = Buffer :: new ( ) ;
676
676
render_impl (
677
677
& mut buffer,
678
678
cx,
@@ -693,7 +693,7 @@ pub(crate) fn render_impls(
693
693
} )
694
694
. collect :: < Vec < _ > > ( ) ;
695
695
rendered_impls. sort ( ) ;
696
- w. write_str ( & rendered_impls. join ( "" ) ) ;
696
+ w. write_str ( & rendered_impls. join ( "" ) ) . unwrap ( ) ;
697
697
}
698
698
699
699
/// Build a (possibly empty) `href` attribute (a key-value pair) for the given associated item.
@@ -1080,61 +1080,68 @@ impl<'a> AssocItemLink<'a> {
1080
1080
}
1081
1081
}
1082
1082
1083
- fn write_impl_section_heading ( w : & mut Buffer , title : & str , id : & str ) {
1083
+ fn write_impl_section_heading ( mut w : impl fmt :: Write , title : & str , id : & str ) {
1084
1084
write ! (
1085
1085
w,
1086
1086
"<h2 id=\" {id}\" class=\" small-section-header\" >\
1087
1087
{title}\
1088
1088
<a href=\" #{id}\" class=\" anchor\" >§</a>\
1089
1089
</h2>"
1090
- ) ;
1090
+ )
1091
+ . unwrap ( ) ;
1091
1092
}
1092
1093
1093
1094
pub ( crate ) fn render_all_impls (
1094
- w : & mut Buffer ,
1095
+ mut w : impl Write ,
1095
1096
cx : & mut Context < ' _ > ,
1096
1097
containing_item : & clean:: Item ,
1097
1098
concrete : & [ & Impl ] ,
1098
1099
synthetic : & [ & Impl ] ,
1099
1100
blanket_impl : & [ & Impl ] ,
1100
1101
) {
1101
- let mut impls = Buffer :: empty_from ( w ) ;
1102
+ let mut impls = Buffer :: html ( ) ;
1102
1103
render_impls ( cx, & mut impls, concrete, containing_item, true ) ;
1103
1104
let impls = impls. into_inner ( ) ;
1104
1105
if !impls. is_empty ( ) {
1105
- write_impl_section_heading ( w, "Trait Implementations" , "trait-implementations" ) ;
1106
- write ! ( w, "<div id=\" trait-implementations-list\" >{}</div>" , impls) ;
1106
+ write_impl_section_heading ( & mut w, "Trait Implementations" , "trait-implementations" ) ;
1107
+ write ! ( w, "<div id=\" trait-implementations-list\" >{}</div>" , impls) . unwrap ( ) ;
1107
1108
}
1108
1109
1109
1110
if !synthetic. is_empty ( ) {
1110
- write_impl_section_heading ( w, "Auto Trait Implementations" , "synthetic-implementations" ) ;
1111
- w. write_str ( "<div id=\" synthetic-implementations-list\" >" ) ;
1112
- render_impls ( cx, w, synthetic, containing_item, false ) ;
1113
- w. write_str ( "</div>" ) ;
1111
+ write_impl_section_heading (
1112
+ & mut w,
1113
+ "Auto Trait Implementations" ,
1114
+ "synthetic-implementations" ,
1115
+ ) ;
1116
+ w. write_str ( "<div id=\" synthetic-implementations-list\" >" ) . unwrap ( ) ;
1117
+ render_impls ( cx, & mut w, synthetic, containing_item, false ) ;
1118
+ w. write_str ( "</div>" ) . unwrap ( ) ;
1114
1119
}
1115
1120
1116
1121
if !blanket_impl. is_empty ( ) {
1117
- write_impl_section_heading ( w, "Blanket Implementations" , "blanket-implementations" ) ;
1118
- w. write_str ( "<div id=\" blanket-implementations-list\" >" ) ;
1119
- render_impls ( cx, w, blanket_impl, containing_item, false ) ;
1120
- w. write_str ( "</div>" ) ;
1122
+ write_impl_section_heading ( & mut w, "Blanket Implementations" , "blanket-implementations" ) ;
1123
+ w. write_str ( "<div id=\" blanket-implementations-list\" >" ) . unwrap ( ) ;
1124
+ render_impls ( cx, & mut w, blanket_impl, containing_item, false ) ;
1125
+ w. write_str ( "</div>" ) . unwrap ( ) ;
1121
1126
}
1122
1127
}
1123
1128
1124
- fn render_assoc_items (
1125
- w : & mut Buffer ,
1126
- cx : & mut Context < ' _ > ,
1127
- containing_item : & clean:: Item ,
1129
+ fn render_assoc_items < ' a , ' cx : ' a > (
1130
+ cx : & ' a mut Context < ' cx > ,
1131
+ containing_item : & ' a clean:: Item ,
1128
1132
it : DefId ,
1129
- what : AssocItemRender < ' _ > ,
1130
- ) {
1133
+ what : AssocItemRender < ' a > ,
1134
+ ) -> impl fmt :: Display + ' a + Captures < ' cx > {
1131
1135
let mut derefs = DefIdSet :: default ( ) ;
1132
1136
derefs. insert ( it) ;
1133
- render_assoc_items_inner ( w, cx, containing_item, it, what, & mut derefs)
1137
+ display_fn ( move |f| {
1138
+ render_assoc_items_inner ( f, cx, containing_item, it, what, & mut derefs) ;
1139
+ Ok ( ( ) )
1140
+ } )
1134
1141
}
1135
1142
1136
1143
fn render_assoc_items_inner (
1137
- w : & mut Buffer ,
1144
+ mut w : & mut dyn fmt :: Write ,
1138
1145
cx : & mut Context < ' _ > ,
1139
1146
containing_item : & clean:: Item ,
1140
1147
it : DefId ,
@@ -1147,7 +1154,7 @@ fn render_assoc_items_inner(
1147
1154
let Some ( v) = cache. impls . get ( & it) else { return } ;
1148
1155
let ( non_trait, traits) : ( Vec < _ > , _ ) = v. iter ( ) . partition ( |i| i. inner_impl ( ) . trait_ . is_none ( ) ) ;
1149
1156
if !non_trait. is_empty ( ) {
1150
- let mut tmp_buf = Buffer :: empty_from ( w ) ;
1157
+ let mut tmp_buf = Buffer :: html ( ) ;
1151
1158
let ( render_mode, id) = match what {
1152
1159
AssocItemRender :: All => {
1153
1160
write_impl_section_heading ( & mut tmp_buf, "Implementations" , "implementations" ) ;
@@ -1171,7 +1178,7 @@ fn render_assoc_items_inner(
1171
1178
( RenderMode :: ForDeref { mut_ : deref_mut_ } , cx. derive_id ( id) )
1172
1179
}
1173
1180
} ;
1174
- let mut impls_buf = Buffer :: empty_from ( w ) ;
1181
+ let mut impls_buf = Buffer :: html ( ) ;
1175
1182
for i in & non_trait {
1176
1183
render_impl (
1177
1184
& mut impls_buf,
@@ -1191,10 +1198,10 @@ fn render_assoc_items_inner(
1191
1198
) ;
1192
1199
}
1193
1200
if !impls_buf. is_empty ( ) {
1194
- w . push_buffer ( tmp_buf ) ;
1195
- write ! ( w, "<div id=\" {}\" >" , id) ;
1196
- w . push_buffer ( impls_buf ) ;
1197
- w. write_str ( "</div>" ) ;
1201
+ write ! ( w , "{}" , tmp_buf . into_inner ( ) ) . unwrap ( ) ;
1202
+ write ! ( w, "<div id=\" {}\" >" , id) . unwrap ( ) ;
1203
+ write ! ( w , "{}" , impls_buf . into_inner ( ) ) . unwrap ( ) ;
1204
+ w. write_str ( "</div>" ) . unwrap ( ) ;
1198
1205
}
1199
1206
}
1200
1207
@@ -1204,7 +1211,7 @@ fn render_assoc_items_inner(
1204
1211
if let Some ( impl_) = deref_impl {
1205
1212
let has_deref_mut =
1206
1213
traits. iter ( ) . any ( |t| t. trait_did ( ) == cx. tcx ( ) . lang_items ( ) . deref_mut_trait ( ) ) ;
1207
- render_deref_methods ( w, cx, impl_, containing_item, has_deref_mut, derefs) ;
1214
+ render_deref_methods ( & mut w, cx, impl_, containing_item, has_deref_mut, derefs) ;
1208
1215
}
1209
1216
1210
1217
// If we were already one level into rendering deref methods, we don't want to render
@@ -1223,7 +1230,7 @@ fn render_assoc_items_inner(
1223
1230
}
1224
1231
1225
1232
fn render_deref_methods (
1226
- w : & mut Buffer ,
1233
+ mut w : impl Write ,
1227
1234
cx : & mut Context < ' _ > ,
1228
1235
impl_ : & Impl ,
1229
1236
container_item : & clean:: Item ,
@@ -1255,10 +1262,10 @@ fn render_deref_methods(
1255
1262
return ;
1256
1263
}
1257
1264
}
1258
- render_assoc_items_inner ( w, cx, container_item, did, what, derefs) ;
1265
+ render_assoc_items_inner ( & mut w, cx, container_item, did, what, derefs) ;
1259
1266
} else if let Some ( prim) = target. primitive_type ( ) {
1260
1267
if let Some ( & did) = cache. primitive_locations . get ( & prim) {
1261
- render_assoc_items_inner ( w, cx, container_item, did, what, derefs) ;
1268
+ render_assoc_items_inner ( & mut w, cx, container_item, did, what, derefs) ;
1262
1269
}
1263
1270
}
1264
1271
}
0 commit comments