@@ -1595,9 +1595,20 @@ fn item_struct(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean
15951595 cx : std:: cell:: RefCell < & ' a mut Context < ' cx > > ,
15961596 it : & ' a clean:: Item ,
15971597 s : & ' a clean:: Struct ,
1598+ should_render_fields : bool ,
15981599 }
15991600
16001601 impl < ' a , ' cx : ' a > ItemStruct < ' a , ' cx > {
1602+ fn new (
1603+ cx : std:: cell:: RefCell < & ' a mut Context < ' cx > > ,
1604+ it : & ' a clean:: Item ,
1605+ s : & ' a clean:: Struct ,
1606+ ) -> Self {
1607+ let should_render_fields = matches ! ( s. ctor_kind, None | Some ( CtorKind :: Fn ) )
1608+ && struct_field_items ( s) . peekable ( ) . peek ( ) . is_some ( ) ;
1609+ Self { cx, it, s, should_render_fields }
1610+ }
1611+
16011612 fn render_struct < ' b > ( & ' b self ) -> impl fmt:: Display + Captures < ' a > + ' b + Captures < ' cx > {
16021613 display_fn ( move |f| {
16031614 let cx = self . cx . borrow ( ) ;
@@ -1622,18 +1633,6 @@ fn item_struct(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean
16221633 } )
16231634 }
16241635
1625- fn fields ( & self ) -> impl Iterator < Item = ( & clean:: Item , & clean:: Type ) > {
1626- self . s . fields . iter ( ) . filter_map ( |item| match * item. kind {
1627- clean:: StructFieldItem ( ref ty) => Some ( ( item, ty) ) ,
1628- _ => None ,
1629- } )
1630- }
1631-
1632- fn should_render_fields ( & self ) -> bool {
1633- matches ! ( self . s. ctor_kind, None | Some ( CtorKind :: Fn ) )
1634- && self . fields ( ) . peekable ( ) . peek ( ) . is_some ( )
1635- }
1636-
16371636 fn render_field_in_span < ' b > (
16381637 & ' b self ,
16391638 index : & ' b usize ,
@@ -1691,7 +1690,14 @@ fn item_struct(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean
16911690 }
16921691 }
16931692
1694- ItemStruct { cx : std:: cell:: RefCell :: new ( cx) , it, s } . render_into ( w) . unwrap ( ) ;
1693+ ItemStruct :: new ( std:: cell:: RefCell :: new ( cx) , it, s) . render_into ( w) . unwrap ( ) ;
1694+ }
1695+
1696+ fn struct_field_items ( s : & clean:: Struct ) -> impl Iterator < Item = ( & clean:: Item , & clean:: Type ) > {
1697+ s. fields . iter ( ) . filter_map ( |item| match * item. kind {
1698+ clean:: StructFieldItem ( ref ty) => Some ( ( item, ty) ) ,
1699+ _ => None ,
1700+ } )
16951701}
16961702
16971703fn item_static ( w : & mut impl fmt:: Write , cx : & mut Context < ' _ > , it : & clean:: Item , s : & clean:: Static ) {
0 commit comments