@@ -11,8 +11,8 @@ use rustc_span::symbol::{kw, sym, Symbol};
11
11
12
12
use super :: {
13
13
collect_paths_for_type, document, ensure_trailing_slash, item_ty_to_strs, notable_traits_decl,
14
- render_assoc_item, render_assoc_items, render_attributes , render_impl ,
15
- render_stability_since_raw, write_srclink, AssocItemLink , Context ,
14
+ render_assoc_item, render_assoc_items, render_attributes_in_code , render_attributes_in_pre ,
15
+ render_impl , render_stability_since_raw, write_srclink, AssocItemLink , Context ,
16
16
} ;
17
17
use crate :: clean:: { self , GetDefId } ;
18
18
use crate :: formats:: cache:: Cache ;
@@ -138,11 +138,15 @@ fn should_hide_fields(n_fields: usize) -> bool {
138
138
}
139
139
140
140
fn toggle_open ( w : & mut Buffer , text : & str ) {
141
- write ! ( w, "<div class=\" docblock type-contents-toggle\" data-toggle-text=\" {}\" >" , text) ;
141
+ write ! (
142
+ w,
143
+ "<details class=\" type-contents-toggle\" ><summary class=\" hideme\" ><span>Show {}</span></summary>" ,
144
+ text
145
+ ) ;
142
146
}
143
147
144
148
fn toggle_close ( w : & mut Buffer ) {
145
- w. write_str ( "</div >" ) ;
149
+ w. write_str ( "</details >" ) ;
146
150
}
147
151
148
152
fn item_module ( w : & mut Buffer , cx : & Context < ' _ > , item : & clean:: Item , items : & [ clean:: Item ] ) {
@@ -391,7 +395,7 @@ fn item_function(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, f: &clean::
391
395
)
392
396
. len ( ) ;
393
397
w. write_str ( "<pre class=\" rust fn\" >" ) ;
394
- render_attributes ( w, it, false ) ;
398
+ render_attributes_in_pre ( w, it, "" ) ;
395
399
write ! (
396
400
w,
397
401
"{vis}{constness}{asyncness}{unsafety}{abi}fn \
@@ -420,7 +424,7 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
420
424
// Output the trait definition
421
425
wrap_into_docblock ( w, |w| {
422
426
w. write_str ( "<pre class=\" rust trait\" >" ) ;
423
- render_attributes ( w, it, true ) ;
427
+ render_attributes_in_pre ( w, it, "" ) ;
424
428
write ! (
425
429
w,
426
430
"{}{}{}trait {}{}{}" ,
@@ -729,7 +733,7 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
729
733
730
734
fn item_trait_alias ( w : & mut Buffer , cx : & Context < ' _ > , it : & clean:: Item , t : & clean:: TraitAlias ) {
731
735
w. write_str ( "<pre class=\" rust trait-alias\" >" ) ;
732
- render_attributes ( w, it, false ) ;
736
+ render_attributes_in_pre ( w, it, "" ) ;
733
737
write ! (
734
738
w,
735
739
"trait {}{}{} = {};</pre>" ,
@@ -750,7 +754,7 @@ fn item_trait_alias(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clea
750
754
751
755
fn item_opaque_ty ( w : & mut Buffer , cx : & Context < ' _ > , it : & clean:: Item , t : & clean:: OpaqueTy ) {
752
756
w. write_str ( "<pre class=\" rust opaque\" >" ) ;
753
- render_attributes ( w, it, false ) ;
757
+ render_attributes_in_pre ( w, it, "" ) ;
754
758
write ! (
755
759
w,
756
760
"type {}{}{where_clause} = impl {bounds};</pre>" ,
@@ -771,7 +775,7 @@ fn item_opaque_ty(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean:
771
775
772
776
fn item_typedef ( w : & mut Buffer , cx : & Context < ' _ > , it : & clean:: Item , t : & clean:: Typedef ) {
773
777
w. write_str ( "<pre class=\" rust typedef\" >" ) ;
774
- render_attributes ( w, it, false ) ;
778
+ render_attributes_in_pre ( w, it, "" ) ;
775
779
write ! (
776
780
w,
777
781
"type {}{}{where_clause} = {type_};</pre>" ,
@@ -793,7 +797,7 @@ fn item_typedef(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::T
793
797
fn item_union ( w : & mut Buffer , cx : & Context < ' _ > , it : & clean:: Item , s : & clean:: Union ) {
794
798
wrap_into_docblock ( w, |w| {
795
799
w. write_str ( "<pre class=\" rust union\" >" ) ;
796
- render_attributes ( w, it, true ) ;
800
+ render_attributes_in_pre ( w, it, "" ) ;
797
801
render_union ( w, it, Some ( & s. generics ) , & s. fields , "" , true , cx) ;
798
802
w. write_str ( "</pre>" )
799
803
} ) ;
@@ -839,7 +843,7 @@ fn item_union(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::Uni
839
843
fn item_enum ( w : & mut Buffer , cx : & Context < ' _ > , it : & clean:: Item , e : & clean:: Enum ) {
840
844
wrap_into_docblock ( w, |w| {
841
845
w. write_str ( "<pre class=\" rust enum\" >" ) ;
842
- render_attributes ( w, it, true ) ;
846
+ render_attributes_in_pre ( w, it, "" ) ;
843
847
write ! (
844
848
w,
845
849
"{}enum {}{}{}" ,
@@ -1019,7 +1023,7 @@ fn item_primitive(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item) {
1019
1023
1020
1024
fn item_constant ( w : & mut Buffer , cx : & Context < ' _ > , it : & clean:: Item , c : & clean:: Constant ) {
1021
1025
w. write_str ( "<pre class=\" rust const\" >" ) ;
1022
- render_attributes ( w, it, false ) ;
1026
+ render_attributes_in_code ( w, it) ;
1023
1027
1024
1028
write ! (
1025
1029
w,
@@ -1058,7 +1062,7 @@ fn item_constant(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, c: &clean::
1058
1062
fn item_struct ( w : & mut Buffer , cx : & Context < ' _ > , it : & clean:: Item , s : & clean:: Struct ) {
1059
1063
wrap_into_docblock ( w, |w| {
1060
1064
w. write_str ( "<pre class=\" rust struct\" >" ) ;
1061
- render_attributes ( w, it, true ) ;
1065
+ render_attributes_in_code ( w, it) ;
1062
1066
render_struct ( w, it, Some ( & s. generics ) , s. struct_type , & s. fields , "" , true , cx) ;
1063
1067
w. write_str ( "</pre>" )
1064
1068
} ) ;
@@ -1107,7 +1111,7 @@ fn item_struct(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::St
1107
1111
1108
1112
fn item_static ( w : & mut Buffer , cx : & Context < ' _ > , it : & clean:: Item , s : & clean:: Static ) {
1109
1113
w. write_str ( "<pre class=\" rust static\" >" ) ;
1110
- render_attributes ( w, it, false ) ;
1114
+ render_attributes_in_code ( w, it) ;
1111
1115
write ! (
1112
1116
w,
1113
1117
"{vis}static {mutability}{name}: {typ}</pre>" ,
@@ -1121,7 +1125,7 @@ fn item_static(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::St
1121
1125
1122
1126
fn item_foreign_type ( w : & mut Buffer , cx : & Context < ' _ > , it : & clean:: Item ) {
1123
1127
w. write_str ( "<pre class=\" rust foreigntype\" >extern {\n " ) ;
1124
- render_attributes ( w, it, false ) ;
1128
+ render_attributes_in_code ( w, it) ;
1125
1129
write ! (
1126
1130
w,
1127
1131
" {}type {};\n }}</pre>" ,
@@ -1304,10 +1308,8 @@ fn render_union(
1304
1308
}
1305
1309
1306
1310
write ! ( w, " {{\n {}" , tab) ;
1307
- let count_fields = fields
1308
- . iter ( )
1309
- . filter ( |f| matches ! ( clean:: StructFieldItem ( ..) , * f. kind) )
1310
- . count ( ) ;
1311
+ let count_fields =
1312
+ fields. iter ( ) . filter ( |f| matches ! ( * f. kind, clean:: StructFieldItem ( ..) ) ) . count ( ) ;
1311
1313
let toggle = should_hide_fields ( count_fields) ;
1312
1314
if toggle {
1313
1315
toggle_open ( w, "fields" ) ;
@@ -1361,10 +1363,8 @@ fn render_struct(
1361
1363
write ! ( w, "{}" , print_where_clause( g, cx. cache( ) , cx. tcx( ) , 0 , true ) , )
1362
1364
}
1363
1365
w. write_str ( " {" ) ;
1364
- let count_fields = fields
1365
- . iter ( )
1366
- . filter ( |f| matches ! ( clean:: StructFieldItem ( ..) = * f. kind) )
1367
- . count ( ) ;
1366
+ let count_fields =
1367
+ fields. iter ( ) . filter ( |f| matches ! ( * f. kind, clean:: StructFieldItem ( ..) ) ) . count ( ) ;
1368
1368
let has_visible_fields = count_fields > 0 ;
1369
1369
let toggle = should_hide_fields ( count_fields) ;
1370
1370
if toggle {
0 commit comments