@@ -22,8 +22,8 @@ use super::{
22
22
item_ty_to_section, notable_traits_button, notable_traits_json, render_all_impls,
23
23
render_assoc_item, render_assoc_items, render_attributes_in_code, render_attributes_in_pre,
24
24
render_impl, render_rightside, render_stability_since_raw,
25
- render_stability_since_raw_with_extra, AssocItemLink , AssocItemRender , Context ,
26
- ImplRenderingParameters , RenderMode ,
25
+ render_stability_since_raw_with_extra, write_section_heading , AssocItemLink , AssocItemRender ,
26
+ Context , ImplRenderingParameters , RenderMode ,
27
27
} ;
28
28
use crate :: clean;
29
29
use crate :: config:: ModuleSorting ;
@@ -428,13 +428,12 @@ fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items:
428
428
w. write_str ( ITEM_TABLE_CLOSE ) ;
429
429
}
430
430
last_section = Some ( my_section) ;
431
- write ! (
431
+ write_section_heading (
432
432
w,
433
- "<h2 id=\" {id}\" class=\" section-header\" >\
434
- {name}<a href=\" #{id}\" class=\" anchor\" >§</a>\
435
- </h2>{ITEM_TABLE_OPEN}",
436
- id = cx. derive_id( my_section. id( ) ) ,
437
- name = my_section. name( ) ,
433
+ my_section. name ( ) ,
434
+ & cx. derive_id ( my_section. id ( ) ) ,
435
+ None ,
436
+ ITEM_TABLE_OPEN ,
438
437
) ;
439
438
}
440
439
@@ -824,16 +823,6 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
824
823
// Trait documentation
825
824
write ! ( w, "{}" , document( cx, it, None , HeadingOffset :: H2 ) ) ;
826
825
827
- fn write_small_section_header ( w : & mut Buffer , id : & str , title : & str , extra_content : & str ) {
828
- write ! (
829
- w,
830
- "<h2 id=\" {0}\" class=\" section-header\" >\
831
- {1}<a href=\" #{0}\" class=\" anchor\" >§</a>\
832
- </h2>{2}",
833
- id, title, extra_content
834
- )
835
- }
836
-
837
826
fn trait_item ( w : & mut Buffer , cx : & mut Context < ' _ > , m : & clean:: Item , t : & clean:: Item ) {
838
827
let name = m. name . unwrap ( ) ;
839
828
info ! ( "Documenting {name} on {ty_name:?}" , ty_name = t. name) ;
@@ -867,10 +856,11 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
867
856
}
868
857
869
858
if !required_types. is_empty ( ) {
870
- write_small_section_header (
859
+ write_section_heading (
871
860
w,
872
- "required-associated-types" ,
873
861
"Required Associated Types" ,
862
+ "required-associated-types" ,
863
+ None ,
874
864
"<div class=\" methods\" >" ,
875
865
) ;
876
866
for t in required_types {
@@ -879,10 +869,11 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
879
869
w. write_str ( "</div>" ) ;
880
870
}
881
871
if !provided_types. is_empty ( ) {
882
- write_small_section_header (
872
+ write_section_heading (
883
873
w,
884
- "provided-associated-types" ,
885
874
"Provided Associated Types" ,
875
+ "provided-associated-types" ,
876
+ None ,
886
877
"<div class=\" methods\" >" ,
887
878
) ;
888
879
for t in provided_types {
@@ -892,10 +883,11 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
892
883
}
893
884
894
885
if !required_consts. is_empty ( ) {
895
- write_small_section_header (
886
+ write_section_heading (
896
887
w,
897
- "required-associated-consts" ,
898
888
"Required Associated Constants" ,
889
+ "required-associated-consts" ,
890
+ None ,
899
891
"<div class=\" methods\" >" ,
900
892
) ;
901
893
for t in required_consts {
@@ -904,10 +896,11 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
904
896
w. write_str ( "</div>" ) ;
905
897
}
906
898
if !provided_consts. is_empty ( ) {
907
- write_small_section_header (
899
+ write_section_heading (
908
900
w,
909
- "provided-associated-consts" ,
910
901
"Provided Associated Constants" ,
902
+ "provided-associated-consts" ,
903
+ None ,
911
904
"<div class=\" methods\" >" ,
912
905
) ;
913
906
for t in provided_consts {
@@ -918,10 +911,11 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
918
911
919
912
// Output the documentation for each function individually
920
913
if !required_methods. is_empty ( ) || must_implement_one_of_functions. is_some ( ) {
921
- write_small_section_header (
914
+ write_section_heading (
922
915
w,
923
- "required-methods" ,
924
916
"Required Methods" ,
917
+ "required-methods" ,
918
+ None ,
925
919
"<div class=\" methods\" >" ,
926
920
) ;
927
921
@@ -939,10 +933,11 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
939
933
w. write_str ( "</div>" ) ;
940
934
}
941
935
if !provided_methods. is_empty ( ) {
942
- write_small_section_header (
936
+ write_section_heading (
943
937
w,
944
- "provided-methods" ,
945
938
"Provided Methods" ,
939
+ "provided-methods" ,
940
+ None ,
946
941
"<div class=\" methods\" >" ,
947
942
) ;
948
943
for m in provided_methods {
@@ -959,10 +954,11 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
959
954
let mut extern_crates = FxHashSet :: default ( ) ;
960
955
961
956
if !t. is_object_safe ( cx. tcx ( ) ) {
962
- write_small_section_header (
957
+ write_section_heading (
963
958
w,
964
- "object-safety" ,
965
959
"Object Safety" ,
960
+ "object-safety" ,
961
+ None ,
966
962
& format ! (
967
963
"<div class=\" object-safety-info\" >This trait is <b>not</b> \
968
964
<a href=\" {base}/reference/items/traits.html#object-safety\" >\
@@ -1006,7 +1002,7 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
1006
1002
foreign. sort_by_cached_key ( |i| ImplString :: new ( i, cx) ) ;
1007
1003
1008
1004
if !foreign. is_empty ( ) {
1009
- write_small_section_header ( w, "foreign-impls" , " Implementations on Foreign Types", "" ) ;
1005
+ write_section_heading ( w, "Implementations on Foreign Types" , "foreign-impls" , None , "" ) ;
1010
1006
1011
1007
for implementor in foreign {
1012
1008
let provided_methods = implementor. inner_impl ( ) . provided_trait_methods ( tcx) ;
@@ -1031,10 +1027,11 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
1031
1027
}
1032
1028
}
1033
1029
1034
- write_small_section_header (
1030
+ write_section_heading (
1035
1031
w,
1036
- "implementors" ,
1037
1032
"Implementors" ,
1033
+ "implementors" ,
1034
+ None ,
1038
1035
"<div id=\" implementors-list\" >" ,
1039
1036
) ;
1040
1037
for implementor in concrete {
@@ -1043,10 +1040,11 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
1043
1040
w. write_str ( "</div>" ) ;
1044
1041
1045
1042
if t. is_auto ( tcx) {
1046
- write_small_section_header (
1043
+ write_section_heading (
1047
1044
w,
1048
- "synthetic-implementors" ,
1049
1045
"Auto implementors" ,
1046
+ "synthetic-implementors" ,
1047
+ None ,
1050
1048
"<div id=\" synthetic-implementors-list\" >" ,
1051
1049
) ;
1052
1050
for implementor in synthetic {
@@ -1064,18 +1062,20 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
1064
1062
} else {
1065
1063
// even without any implementations to write in, we still want the heading and list, so the
1066
1064
// implementors javascript file pulled in below has somewhere to write the impls into
1067
- write_small_section_header (
1065
+ write_section_heading (
1068
1066
w,
1069
- "implementors" ,
1070
1067
"Implementors" ,
1068
+ "implementors" ,
1069
+ None ,
1071
1070
"<div id=\" implementors-list\" ></div>" ,
1072
1071
) ;
1073
1072
1074
1073
if t. is_auto ( tcx) {
1075
- write_small_section_header (
1074
+ write_section_heading (
1076
1075
w,
1077
- "synthetic-implementors" ,
1078
1076
"Auto implementors" ,
1077
+ "synthetic-implementors" ,
1078
+ None ,
1079
1079
"<div id=\" synthetic-implementors-list\" ></div>" ,
1080
1080
) ;
1081
1081
}
@@ -1258,11 +1258,7 @@ fn item_type_alias(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &c
1258
1258
write ! ( w, "{}" , document( cx, it, None , HeadingOffset :: H2 ) ) ;
1259
1259
1260
1260
if let Some ( inner_type) = & t. inner_type {
1261
- write ! (
1262
- w,
1263
- "<h2 id=\" aliased-type\" class=\" section-header\" >\
1264
- Aliased Type<a href=\" #aliased-type\" class=\" anchor\" >§</a></h2>"
1265
- ) ;
1261
+ write_section_heading ( w, "Aliased Type" , "aliased-type" , None , "" ) ;
1266
1262
1267
1263
match inner_type {
1268
1264
clean:: TypeAliasInnerType :: Enum { variants, is_non_exhaustive } => {
@@ -1683,16 +1679,14 @@ fn item_variants(
1683
1679
enum_def_id : DefId ,
1684
1680
) {
1685
1681
let tcx = cx. tcx ( ) ;
1686
- write ! (
1682
+ write_section_heading (
1687
1683
w,
1688
- "<h2 id=\" variants\" class=\" variants section-header\" >\
1689
- Variants{}<a href=\" #variants\" class=\" anchor\" >§</a>\
1690
- </h2>\
1691
- {}\
1692
- <div class=\" variants\" >",
1693
- document_non_exhaustive_header( it) ,
1694
- document_non_exhaustive( it)
1684
+ & format ! ( "Variants{}" , document_non_exhaustive_header( it) ) ,
1685
+ "variants" ,
1686
+ Some ( "variants" ) ,
1687
+ format ! ( "{}<div class=\" variants\" >" , document_non_exhaustive( it) ) ,
1695
1688
) ;
1689
+
1696
1690
let should_show_enum_discriminant = should_show_enum_discriminant ( cx, enum_def_id, variants) ;
1697
1691
for ( index, variant) in variants. iter_enumerated ( ) {
1698
1692
if variant. is_stripped ( ) {
@@ -1933,16 +1927,12 @@ fn item_fields(
1933
1927
. peekable ( ) ;
1934
1928
if let None | Some ( CtorKind :: Fn ) = ctor_kind {
1935
1929
if fields. peek ( ) . is_some ( ) {
1936
- write ! (
1937
- w,
1938
- "<h2 id=\" fields\" class=\" fields section-header\" >\
1939
- {}{}<a href=\" #fields\" class=\" anchor\" >§</a>\
1940
- </h2>\
1941
- {}",
1930
+ let title = format ! (
1931
+ "{}{}" ,
1942
1932
if ctor_kind. is_none( ) { "Fields" } else { "Tuple Fields" } ,
1943
1933
document_non_exhaustive_header( it) ,
1944
- document_non_exhaustive( it)
1945
1934
) ;
1935
+ write_section_heading ( w, & title, "fields" , Some ( "fields" ) , document_non_exhaustive ( it) ) ;
1946
1936
for ( index, ( field, ty) ) in fields. enumerate ( ) {
1947
1937
let field_name =
1948
1938
field. name . map_or_else ( || index. to_string ( ) , |sym| sym. as_str ( ) . to_string ( ) ) ;
0 commit comments