@@ -11,8 +11,8 @@ use rustc_span::symbol::{kw, sym, Symbol};
1111
1212use super :: {
1313 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 ,
1616} ;
1717use crate :: clean:: { self , GetDefId } ;
1818use crate :: formats:: cache:: Cache ;
@@ -138,11 +138,15 @@ fn should_hide_fields(n_fields: usize) -> bool {
138138}
139139
140140fn 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+ ) ;
142146}
143147
144148fn toggle_close ( w : & mut Buffer ) {
145- w. write_str ( "</div >" ) ;
149+ w. write_str ( "</details >" ) ;
146150}
147151
148152fn 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::
391395 )
392396 . len ( ) ;
393397 w. write_str ( "<pre class=\" rust fn\" >" ) ;
394- render_attributes ( w, it, false ) ;
398+ render_attributes_in_pre ( w, it, "" ) ;
395399 write ! (
396400 w,
397401 "{vis}{constness}{asyncness}{unsafety}{abi}fn \
@@ -420,7 +424,7 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
420424 // Output the trait definition
421425 wrap_into_docblock ( w, |w| {
422426 w. write_str ( "<pre class=\" rust trait\" >" ) ;
423- render_attributes ( w, it, true ) ;
427+ render_attributes_in_pre ( w, it, "" ) ;
424428 write ! (
425429 w,
426430 "{}{}{}trait {}{}{}" ,
@@ -729,7 +733,7 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
729733
730734fn item_trait_alias ( w : & mut Buffer , cx : & Context < ' _ > , it : & clean:: Item , t : & clean:: TraitAlias ) {
731735 w. write_str ( "<pre class=\" rust trait-alias\" >" ) ;
732- render_attributes ( w, it, false ) ;
736+ render_attributes_in_pre ( w, it, "" ) ;
733737 write ! (
734738 w,
735739 "trait {}{}{} = {};</pre>" ,
@@ -750,7 +754,7 @@ fn item_trait_alias(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clea
750754
751755fn item_opaque_ty ( w : & mut Buffer , cx : & Context < ' _ > , it : & clean:: Item , t : & clean:: OpaqueTy ) {
752756 w. write_str ( "<pre class=\" rust opaque\" >" ) ;
753- render_attributes ( w, it, false ) ;
757+ render_attributes_in_pre ( w, it, "" ) ;
754758 write ! (
755759 w,
756760 "type {}{}{where_clause} = impl {bounds};</pre>" ,
@@ -771,7 +775,7 @@ fn item_opaque_ty(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean:
771775
772776fn item_typedef ( w : & mut Buffer , cx : & Context < ' _ > , it : & clean:: Item , t : & clean:: Typedef ) {
773777 w. write_str ( "<pre class=\" rust typedef\" >" ) ;
774- render_attributes ( w, it, false ) ;
778+ render_attributes_in_pre ( w, it, "" ) ;
775779 write ! (
776780 w,
777781 "type {}{}{where_clause} = {type_};</pre>" ,
@@ -793,7 +797,7 @@ fn item_typedef(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::T
793797fn item_union ( w : & mut Buffer , cx : & Context < ' _ > , it : & clean:: Item , s : & clean:: Union ) {
794798 wrap_into_docblock ( w, |w| {
795799 w. write_str ( "<pre class=\" rust union\" >" ) ;
796- render_attributes ( w, it, true ) ;
800+ render_attributes_in_pre ( w, it, "" ) ;
797801 render_union ( w, it, Some ( & s. generics ) , & s. fields , "" , true , cx) ;
798802 w. write_str ( "</pre>" )
799803 } ) ;
@@ -839,7 +843,7 @@ fn item_union(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::Uni
839843fn item_enum ( w : & mut Buffer , cx : & Context < ' _ > , it : & clean:: Item , e : & clean:: Enum ) {
840844 wrap_into_docblock ( w, |w| {
841845 w. write_str ( "<pre class=\" rust enum\" >" ) ;
842- render_attributes ( w, it, true ) ;
846+ render_attributes_in_pre ( w, it, "" ) ;
843847 write ! (
844848 w,
845849 "{}enum {}{}{}" ,
@@ -1019,7 +1023,7 @@ fn item_primitive(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item) {
10191023
10201024fn item_constant ( w : & mut Buffer , cx : & Context < ' _ > , it : & clean:: Item , c : & clean:: Constant ) {
10211025 w. write_str ( "<pre class=\" rust const\" >" ) ;
1022- render_attributes ( w, it, false ) ;
1026+ render_attributes_in_code ( w, it) ;
10231027
10241028 write ! (
10251029 w,
@@ -1058,7 +1062,7 @@ fn item_constant(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, c: &clean::
10581062fn item_struct ( w : & mut Buffer , cx : & Context < ' _ > , it : & clean:: Item , s : & clean:: Struct ) {
10591063 wrap_into_docblock ( w, |w| {
10601064 w. write_str ( "<pre class=\" rust struct\" >" ) ;
1061- render_attributes ( w, it, true ) ;
1065+ render_attributes_in_code ( w, it) ;
10621066 render_struct ( w, it, Some ( & s. generics ) , s. struct_type , & s. fields , "" , true , cx) ;
10631067 w. write_str ( "</pre>" )
10641068 } ) ;
@@ -1107,7 +1111,7 @@ fn item_struct(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::St
11071111
11081112fn item_static ( w : & mut Buffer , cx : & Context < ' _ > , it : & clean:: Item , s : & clean:: Static ) {
11091113 w. write_str ( "<pre class=\" rust static\" >" ) ;
1110- render_attributes ( w, it, false ) ;
1114+ render_attributes_in_code ( w, it) ;
11111115 write ! (
11121116 w,
11131117 "{vis}static {mutability}{name}: {typ}</pre>" ,
@@ -1121,7 +1125,7 @@ fn item_static(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::St
11211125
11221126fn item_foreign_type ( w : & mut Buffer , cx : & Context < ' _ > , it : & clean:: Item ) {
11231127 w. write_str ( "<pre class=\" rust foreigntype\" >extern {\n " ) ;
1124- render_attributes ( w, it, false ) ;
1128+ render_attributes_in_code ( w, it) ;
11251129 write ! (
11261130 w,
11271131 " {}type {};\n }}</pre>" ,
@@ -1304,10 +1308,8 @@ fn render_union(
13041308 }
13051309
13061310 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 ( ) ;
13111313 let toggle = should_hide_fields ( count_fields) ;
13121314 if toggle {
13131315 toggle_open ( w, "fields" ) ;
@@ -1361,10 +1363,8 @@ fn render_struct(
13611363 write ! ( w, "{}" , print_where_clause( g, cx. cache( ) , cx. tcx( ) , 0 , true ) , )
13621364 }
13631365 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 ( ) ;
13681368 let has_visible_fields = count_fields > 0 ;
13691369 let toggle = should_hide_fields ( count_fields) ;
13701370 if toggle {
0 commit comments