@@ -879,45 +879,44 @@ enum AssocConstValue<'a> {
879
879
None ,
880
880
}
881
881
882
- fn assoc_const (
883
- w : & mut String ,
884
- it : & clean:: Item ,
885
- generics : & clean:: Generics ,
886
- ty : & clean:: Type ,
887
- value : AssocConstValue < ' _ > ,
888
- link : AssocItemLink < ' _ > ,
882
+ fn assoc_const < ' a , ' tcx > (
883
+ it : & ' a clean:: Item ,
884
+ generics : & ' a clean:: Generics ,
885
+ ty : & ' a clean:: Type ,
886
+ value : AssocConstValue < ' a > ,
887
+ link : AssocItemLink < ' a > ,
889
888
indent : usize ,
890
- cx : & Context < ' _ > ,
891
- ) {
889
+ cx : & ' a Context < ' tcx > ,
890
+ ) -> impl fmt :: Display + ' a + Captures < ' tcx > {
892
891
let tcx = cx. tcx ( ) ;
893
- write_str (
894
- w ,
895
- format_args ! (
892
+ fmt :: from_fn ( move |w| {
893
+ write ! (
894
+ w ,
896
895
"{indent}{vis}const <a{href} class=\" constant\" >{name}</a>{generics}: {ty}" ,
897
896
indent = " " . repeat( indent) ,
898
897
vis = visibility_print_with_space( it, cx) ,
899
898
href = assoc_href_attr( it, link, cx) . maybe_display( ) ,
900
899
name = it. name. as_ref( ) . unwrap( ) ,
901
900
generics = generics. print( cx) ,
902
901
ty = ty. print( cx) ,
903
- ) ,
904
- ) ;
905
- if let AssocConstValue :: TraitDefault ( konst ) | AssocConstValue :: Impl ( konst ) = value {
906
- // FIXME: `.value()` uses `clean::utils::format_integer_with_underscore_sep` under the
907
- // hood which adds noisy underscores and a type suffix to number literals.
908
- // This hurts readability in this context especially when more complex expressions
909
- // are involved and it doesn't add much of value .
910
- // Find a way to print constants here without all that jazz.
911
- let repr = konst . value ( tcx ) . unwrap_or_else ( || konst . expr ( tcx ) ) ;
912
- if match value {
913
- AssocConstValue :: TraitDefault ( _) => true , // always show
914
- AssocConstValue :: Impl ( _ ) => repr != "_" , // show if there is a meaningful value to show
915
- AssocConstValue :: None => unreachable ! ( ) ,
916
- } {
917
- write_str ( w , format_args ! ( " = {}" , Escape ( & repr ) ) ) ;
902
+ ) ? ;
903
+ if let AssocConstValue :: TraitDefault ( konst ) | AssocConstValue :: Impl ( konst ) = value {
904
+ // FIXME: `.value()` uses `clean::utils::format_integer_with_underscore_sep` under the
905
+ // hood which adds noisy underscores and a type suffix to number literals.
906
+ // This hurts readability in this context especially when more complex expressions
907
+ // are involved and it doesn't add much of value.
908
+ // Find a way to print constants here without all that jazz .
909
+ let repr = konst . value ( tcx ) . unwrap_or_else ( || konst . expr ( tcx ) ) ;
910
+ if match value {
911
+ AssocConstValue :: TraitDefault ( _ ) => true , // always show
912
+ AssocConstValue :: Impl ( _) => repr != "_" , // show if there is a meaningful value to show
913
+ AssocConstValue :: None => unreachable ! ( ) ,
914
+ } {
915
+ write ! ( w , " = {}" , Escape ( & repr ) ) ? ;
916
+ }
918
917
}
919
- }
920
- write_str ( w , format_args ! ( "{}" , print_where_clause ( generics , cx , indent , Ending :: NoNewline ) ) ) ;
918
+ write ! ( w , "{}" , print_where_clause ( generics , cx , indent , Ending :: NoNewline ) )
919
+ } )
921
920
}
922
921
923
922
fn assoc_type (
@@ -1132,36 +1131,57 @@ fn render_assoc_item(
1132
1131
) ,
1133
1132
) ;
1134
1133
}
1135
- clean:: RequiredAssocConstItem ( generics, ty) => assoc_const (
1136
- w,
1137
- item,
1138
- generics,
1139
- ty,
1140
- AssocConstValue :: None ,
1141
- link,
1142
- if parent == ItemType :: Trait { 4 } else { 0 } ,
1143
- cx,
1144
- ) ,
1145
- clean:: ProvidedAssocConstItem ( ci) => assoc_const (
1146
- w,
1147
- item,
1148
- & ci. generics ,
1149
- & ci. type_ ,
1150
- AssocConstValue :: TraitDefault ( & ci. kind ) ,
1151
- link,
1152
- if parent == ItemType :: Trait { 4 } else { 0 } ,
1153
- cx,
1154
- ) ,
1155
- clean:: ImplAssocConstItem ( ci) => assoc_const (
1156
- w,
1157
- item,
1158
- & ci. generics ,
1159
- & ci. type_ ,
1160
- AssocConstValue :: Impl ( & ci. kind ) ,
1161
- link,
1162
- if parent == ItemType :: Trait { 4 } else { 0 } ,
1163
- cx,
1164
- ) ,
1134
+ clean:: RequiredAssocConstItem ( generics, ty) => {
1135
+ write_str (
1136
+ w,
1137
+ format_args ! (
1138
+ "{}" ,
1139
+ assoc_const(
1140
+ item,
1141
+ generics,
1142
+ ty,
1143
+ AssocConstValue :: None ,
1144
+ link,
1145
+ if parent == ItemType :: Trait { 4 } else { 0 } ,
1146
+ cx,
1147
+ )
1148
+ ) ,
1149
+ ) ;
1150
+ }
1151
+ clean:: ProvidedAssocConstItem ( ci) => {
1152
+ write_str (
1153
+ w,
1154
+ format_args ! (
1155
+ "{}" ,
1156
+ assoc_const(
1157
+ item,
1158
+ & ci. generics,
1159
+ & ci. type_,
1160
+ AssocConstValue :: TraitDefault ( & ci. kind) ,
1161
+ link,
1162
+ if parent == ItemType :: Trait { 4 } else { 0 } ,
1163
+ cx,
1164
+ )
1165
+ ) ,
1166
+ ) ;
1167
+ }
1168
+ clean:: ImplAssocConstItem ( ci) => {
1169
+ write_str (
1170
+ w,
1171
+ format_args ! (
1172
+ "{}" ,
1173
+ assoc_const(
1174
+ item,
1175
+ & ci. generics,
1176
+ & ci. type_,
1177
+ AssocConstValue :: Impl ( & ci. kind) ,
1178
+ link,
1179
+ if parent == ItemType :: Trait { 4 } else { 0 } ,
1180
+ cx,
1181
+ )
1182
+ ) ,
1183
+ ) ;
1184
+ }
1165
1185
clean:: RequiredAssocTypeItem ( ref generics, ref bounds) => assoc_type (
1166
1186
w,
1167
1187
item,
@@ -1779,18 +1799,21 @@ fn render_impl(
1779
1799
// Anchors are only used on trait impls.
1780
1800
write_str ( w, format_args ! ( "<a href=\" #{id}\" class=\" anchor\" >§</a>" ) ) ;
1781
1801
}
1782
- w. push_str ( "<h4 class=\" code-header\" >" ) ;
1783
- assoc_const (
1802
+ write_str (
1784
1803
w,
1785
- item,
1786
- generics,
1787
- ty,
1788
- AssocConstValue :: None ,
1789
- link. anchor ( if trait_. is_some ( ) { & source_id } else { & id } ) ,
1790
- 0 ,
1791
- cx,
1804
+ format_args ! (
1805
+ "<h4 class=\" code-header\" >{}</h4></section>" ,
1806
+ assoc_const(
1807
+ item,
1808
+ generics,
1809
+ ty,
1810
+ AssocConstValue :: None ,
1811
+ link. anchor( if trait_. is_some( ) { & source_id } else { & id } ) ,
1812
+ 0 ,
1813
+ cx,
1814
+ )
1815
+ ) ,
1792
1816
) ;
1793
- w. push_str ( "</h4></section>" ) ;
1794
1817
}
1795
1818
clean:: ProvidedAssocConstItem ( ci) | clean:: ImplAssocConstItem ( ci) => {
1796
1819
let source_id = format ! ( "{item_type}.{name}" ) ;
@@ -1804,22 +1827,26 @@ fn render_impl(
1804
1827
// Anchors are only used on trait impls.
1805
1828
write_str ( w, format_args ! ( "<a href=\" #{id}\" class=\" anchor\" >§</a>" ) ) ;
1806
1829
}
1807
- w. push_str ( "<h4 class=\" code-header\" >" ) ;
1808
- assoc_const (
1830
+ write_str (
1809
1831
w,
1810
- item,
1811
- & ci. generics ,
1812
- & ci. type_ ,
1813
- match item. kind {
1814
- clean:: ProvidedAssocConstItem ( _) => AssocConstValue :: TraitDefault ( & ci. kind ) ,
1815
- clean:: ImplAssocConstItem ( _) => AssocConstValue :: Impl ( & ci. kind ) ,
1816
- _ => unreachable ! ( ) ,
1817
- } ,
1818
- link. anchor ( if trait_. is_some ( ) { & source_id } else { & id } ) ,
1819
- 0 ,
1820
- cx,
1832
+ format_args ! (
1833
+ "<h4 class=\" code-header\" >{}</h4></section>" ,
1834
+ assoc_const(
1835
+ item,
1836
+ & ci. generics,
1837
+ & ci. type_,
1838
+ match item. kind {
1839
+ clean:: ProvidedAssocConstItem ( _) =>
1840
+ AssocConstValue :: TraitDefault ( & ci. kind) ,
1841
+ clean:: ImplAssocConstItem ( _) => AssocConstValue :: Impl ( & ci. kind) ,
1842
+ _ => unreachable!( ) ,
1843
+ } ,
1844
+ link. anchor( if trait_. is_some( ) { & source_id } else { & id } ) ,
1845
+ 0 ,
1846
+ cx,
1847
+ )
1848
+ ) ,
1821
1849
) ;
1822
- w. push_str ( "</h4></section>" ) ;
1823
1850
}
1824
1851
clean:: RequiredAssocTypeItem ( ref generics, ref bounds) => {
1825
1852
let source_id = format ! ( "{item_type}.{name}" ) ;
0 commit comments