@@ -919,35 +919,34 @@ fn assoc_const<'a, 'tcx>(
919
919
} )
920
920
}
921
921
922
- fn assoc_type (
923
- w : & mut String ,
924
- it : & clean:: Item ,
925
- generics : & clean:: Generics ,
926
- bounds : & [ clean:: GenericBound ] ,
927
- default : Option < & clean:: Type > ,
928
- link : AssocItemLink < ' _ > ,
922
+ fn assoc_type < ' a , ' tcx > (
923
+ it : & ' a clean:: Item ,
924
+ generics : & ' a clean:: Generics ,
925
+ bounds : & ' a [ clean:: GenericBound ] ,
926
+ default : Option < & ' a clean:: Type > ,
927
+ link : AssocItemLink < ' a > ,
929
928
indent : usize ,
930
- cx : & Context < ' _ > ,
931
- ) {
932
- write_str (
933
- w ,
934
- format_args ! (
929
+ cx : & ' a Context < ' tcx > ,
930
+ ) -> impl fmt :: Display + ' a + Captures < ' tcx > {
931
+ fmt :: from_fn ( move |w| {
932
+ write ! (
933
+ w ,
935
934
"{indent}{vis}type <a{href} class=\" associatedtype\" >{name}</a>{generics}" ,
936
935
indent = " " . repeat( indent) ,
937
936
vis = visibility_print_with_space( it, cx) ,
938
937
href = assoc_href_attr( it, link, cx) . maybe_display( ) ,
939
938
name = it. name. as_ref( ) . unwrap( ) ,
940
939
generics = generics. print( cx) ,
941
- ) ,
942
- ) ;
943
- if !bounds . is_empty ( ) {
944
- write_str ( w , format_args ! ( ": {}" , print_generic_bounds ( bounds , cx ) ) ) ;
945
- }
946
- // Render the default before the where-clause which aligns with the new recommended style. See #89122.
947
- if let Some ( default ) = default {
948
- write_str ( w , format_args ! ( " = {}" , default . print ( cx ) ) ) ;
949
- }
950
- write_str ( w , format_args ! ( "{}" , print_where_clause ( generics , cx , indent , Ending :: NoNewline ) ) ) ;
940
+ ) ? ;
941
+ if !bounds . is_empty ( ) {
942
+ write ! ( w , ": {}" , print_generic_bounds ( bounds , cx ) ) ? ;
943
+ }
944
+ // Render the default before the where-clause which aligns with the new recommended style. See #89122.
945
+ if let Some ( default ) = default {
946
+ write ! ( w , " = {}" , default . print ( cx ) ) ? ;
947
+ }
948
+ write ! ( w , "{}" , print_where_clause ( generics , cx , indent , Ending :: NoNewline ) )
949
+ } )
951
950
}
952
951
953
952
fn assoc_method < ' a , ' tcx > (
@@ -1182,26 +1181,40 @@ fn render_assoc_item(
1182
1181
) ,
1183
1182
) ;
1184
1183
}
1185
- clean:: RequiredAssocTypeItem ( ref generics, ref bounds) => assoc_type (
1186
- w,
1187
- item,
1188
- generics,
1189
- bounds,
1190
- None ,
1191
- link,
1192
- if parent == ItemType :: Trait { 4 } else { 0 } ,
1193
- cx,
1194
- ) ,
1195
- clean:: AssocTypeItem ( ref ty, ref bounds) => assoc_type (
1196
- w,
1197
- item,
1198
- & ty. generics ,
1199
- bounds,
1200
- Some ( ty. item_type . as_ref ( ) . unwrap_or ( & ty. type_ ) ) ,
1201
- link,
1202
- if parent == ItemType :: Trait { 4 } else { 0 } ,
1203
- cx,
1204
- ) ,
1184
+ clean:: RequiredAssocTypeItem ( ref generics, ref bounds) => {
1185
+ write_str (
1186
+ w,
1187
+ format_args ! (
1188
+ "{}" ,
1189
+ assoc_type(
1190
+ item,
1191
+ generics,
1192
+ bounds,
1193
+ None ,
1194
+ link,
1195
+ if parent == ItemType :: Trait { 4 } else { 0 } ,
1196
+ cx,
1197
+ )
1198
+ ) ,
1199
+ ) ;
1200
+ }
1201
+ clean:: AssocTypeItem ( ref ty, ref bounds) => {
1202
+ write_str (
1203
+ w,
1204
+ format_args ! (
1205
+ "{}" ,
1206
+ assoc_type(
1207
+ item,
1208
+ & ty. generics,
1209
+ bounds,
1210
+ Some ( ty. item_type. as_ref( ) . unwrap_or( & ty. type_) ) ,
1211
+ link,
1212
+ if parent == ItemType :: Trait { 4 } else { 0 } ,
1213
+ cx,
1214
+ )
1215
+ ) ,
1216
+ ) ;
1217
+ }
1205
1218
_ => panic ! ( "render_assoc_item called on non-associated-item" ) ,
1206
1219
}
1207
1220
}
@@ -1578,20 +1591,23 @@ fn notable_traits_decl(ty: &clean::Type, cx: &Context<'_>) -> (String, String) {
1578
1591
) ;
1579
1592
for it in & impl_. items {
1580
1593
if let clean:: AssocTypeItem ( ref tydef, ref _bounds) = it. kind {
1581
- out. push_str ( "<div class=\" where\" > " ) ;
1582
1594
let empty_set = FxIndexSet :: default ( ) ;
1583
1595
let src_link = AssocItemLink :: GotoSource ( trait_did. into ( ) , & empty_set) ;
1584
- assoc_type (
1596
+ write_str (
1585
1597
& mut out,
1586
- it,
1587
- & tydef. generics ,
1588
- & [ ] , // intentionally leaving out bounds
1589
- Some ( & tydef. type_ ) ,
1590
- src_link,
1591
- 0 ,
1592
- cx,
1598
+ format_args ! (
1599
+ "<div class=\" where\" > {};</div>" ,
1600
+ assoc_type(
1601
+ it,
1602
+ & tydef. generics,
1603
+ & [ ] , // intentionally leaving out bounds
1604
+ Some ( & tydef. type_) ,
1605
+ src_link,
1606
+ 0 ,
1607
+ cx,
1608
+ )
1609
+ ) ,
1593
1610
) ;
1594
- out. push_str ( ";</div>" ) ;
1595
1611
}
1596
1612
}
1597
1613
}
@@ -1860,18 +1876,21 @@ fn render_impl(
1860
1876
// Anchors are only used on trait impls.
1861
1877
write_str ( w, format_args ! ( "<a href=\" #{id}\" class=\" anchor\" >§</a>" ) ) ;
1862
1878
}
1863
- w. push_str ( "<h4 class=\" code-header\" >" ) ;
1864
- assoc_type (
1879
+ write_str (
1865
1880
w,
1866
- item,
1867
- generics,
1868
- bounds,
1869
- None ,
1870
- link. anchor ( if trait_. is_some ( ) { & source_id } else { & id } ) ,
1871
- 0 ,
1872
- cx,
1881
+ format_args ! (
1882
+ "<h4 class=\" code-header\" >{}</h4></section>" ,
1883
+ assoc_type(
1884
+ item,
1885
+ generics,
1886
+ bounds,
1887
+ None ,
1888
+ link. anchor( if trait_. is_some( ) { & source_id } else { & id } ) ,
1889
+ 0 ,
1890
+ cx,
1891
+ )
1892
+ ) ,
1873
1893
) ;
1874
- w. push_str ( "</h4></section>" ) ;
1875
1894
}
1876
1895
clean:: AssocTypeItem ( tydef, _bounds) => {
1877
1896
let source_id = format ! ( "{item_type}.{name}" ) ;
@@ -1885,18 +1904,21 @@ fn render_impl(
1885
1904
// Anchors are only used on trait impls.
1886
1905
write_str ( w, format_args ! ( "<a href=\" #{id}\" class=\" anchor\" >§</a>" ) ) ;
1887
1906
}
1888
- w. push_str ( "<h4 class=\" code-header\" >" ) ;
1889
- assoc_type (
1907
+ write_str (
1890
1908
w,
1891
- item,
1892
- & tydef. generics ,
1893
- & [ ] , // intentionally leaving out bounds
1894
- Some ( tydef. item_type . as_ref ( ) . unwrap_or ( & tydef. type_ ) ) ,
1895
- link. anchor ( if trait_. is_some ( ) { & source_id } else { & id } ) ,
1896
- 0 ,
1897
- cx,
1909
+ format_args ! (
1910
+ "<h4 class=\" code-header\" >{}</h4></section>" ,
1911
+ assoc_type(
1912
+ item,
1913
+ & tydef. generics,
1914
+ & [ ] , // intentionally leaving out bounds
1915
+ Some ( tydef. item_type. as_ref( ) . unwrap_or( & tydef. type_) ) ,
1916
+ link. anchor( if trait_. is_some( ) { & source_id } else { & id } ) ,
1917
+ 0 ,
1918
+ cx,
1919
+ )
1920
+ ) ,
1898
1921
) ;
1899
- w. push_str ( "</h4></section>" ) ;
1900
1922
}
1901
1923
clean:: StrippedItem ( ..) => return ,
1902
1924
_ => panic ! ( "can't make docs for trait item with name {:?}" , item. name) ,
@@ -2192,18 +2214,21 @@ pub(crate) fn render_impl_summary(
2192
2214
if show_def_docs {
2193
2215
for it in & inner_impl. items {
2194
2216
if let clean:: AssocTypeItem ( ref tydef, ref _bounds) = it. kind {
2195
- w. push_str ( "<div class=\" where\" > " ) ;
2196
- assoc_type (
2217
+ write_str (
2197
2218
w,
2198
- it,
2199
- & tydef. generics ,
2200
- & [ ] , // intentionally leaving out bounds
2201
- Some ( & tydef. type_ ) ,
2202
- AssocItemLink :: Anchor ( None ) ,
2203
- 0 ,
2204
- cx,
2219
+ format_args ! (
2220
+ "<div class=\" where\" > {};</div>" ,
2221
+ assoc_type(
2222
+ it,
2223
+ & tydef. generics,
2224
+ & [ ] , // intentionally leaving out bounds
2225
+ Some ( & tydef. type_) ,
2226
+ AssocItemLink :: Anchor ( None ) ,
2227
+ 0 ,
2228
+ cx,
2229
+ )
2230
+ ) ,
2205
2231
) ;
2206
- w. push_str ( ";</div>" ) ;
2207
2232
}
2208
2233
}
2209
2234
}
0 commit comments