@@ -1457,26 +1457,23 @@ impl<'a, 'cx: 'a> ItemUnion<'a, 'cx> {
14571457 ty. print ( self . cx )
14581458 }
14591459
1460- fn fields_iter (
1461- & self ,
1462- ) -> iter:: Peekable < impl Iterator < Item = ( & ' a clean:: Item , & ' a clean:: Type ) > > {
1463- self . fields
1464- . iter ( )
1465- . filter_map ( |f| match f. kind {
1466- clean:: StructFieldItem ( ref ty) => Some ( ( f, ty) ) ,
1467- _ => None ,
1468- } )
1469- . peekable ( )
1460+ // FIXME (GuillaumeGomez): When <https://github.com/askama-rs/askama/issues/452> is implemented,
1461+ // we can replace the returned value with:
1462+ //
1463+ // `iter::Peekable<impl Iterator<Item = (&'a clean::Item, &'a clean::Type)>>`
1464+ //
1465+ // And update `item_union.html`.
1466+ fn fields_iter ( & self ) -> impl Iterator < Item = ( & ' a clean:: Item , & ' a clean:: Type ) > {
1467+ self . fields . iter ( ) . filter_map ( |f| match f. kind {
1468+ clean:: StructFieldItem ( ref ty) => Some ( ( f, ty) ) ,
1469+ _ => None ,
1470+ } )
14701471 }
14711472
14721473 fn render_attributes_in_pre ( & self ) -> impl fmt:: Display {
14731474 fmt:: from_fn ( move |f| {
1474- if !self . is_type_alias {
1475- for a in self . it . attributes_and_repr ( self . cx . tcx ( ) , self . cx . cache ( ) , false ) {
1476- writeln ! ( f, "{a}" ) ?;
1477- }
1478- } else {
1479- // For now we only render `repr` attributes for type aliases.
1475+ if self . is_type_alias {
1476+ // For now the only attributes we render for type aliases are `repr` attributes.
14801477 if let Some ( repr) = clean:: repr_attributes (
14811478 self . cx . tcx ( ) ,
14821479 self . cx . cache ( ) ,
@@ -1485,6 +1482,10 @@ impl<'a, 'cx: 'a> ItemUnion<'a, 'cx> {
14851482 ) {
14861483 writeln ! ( f, "{repr}" ) ?;
14871484 } ;
1485+ } else {
1486+ for a in self . it . attributes_and_repr ( self . cx . tcx ( ) , self . cx . cache ( ) , false ) {
1487+ writeln ! ( f, "{a}" ) ?;
1488+ }
14881489 }
14891490 Ok ( ( ) )
14901491 } )
@@ -1501,8 +1502,7 @@ fn item_union(cx: &Context<'_>, it: &clean::Item, s: &clean::Union) -> impl fmt:
15011502 is_type_alias : false ,
15021503 def_id : it. def_id ( ) . unwrap ( ) ,
15031504 }
1504- . render_into ( w)
1505- . unwrap ( ) ;
1505+ . render_into ( w) ?;
15061506 Ok ( ( ) )
15071507 } )
15081508}
@@ -1529,31 +1529,31 @@ fn print_tuple_struct_fields(cx: &Context<'_>, s: &[clean::Item]) -> impl Displa
15291529 } )
15301530}
15311531
1532- struct DisplayEnum < ' a > {
1533- variants : & ' a IndexVec < VariantIdx , clean:: Item > ,
1534- generics : & ' a clean:: Generics ,
1532+ struct DisplayEnum < ' clean > {
1533+ variants : & ' clean IndexVec < VariantIdx , clean:: Item > ,
1534+ generics : & ' clean clean:: Generics ,
15351535 is_non_exhaustive : bool ,
15361536 def_id : DefId ,
15371537}
15381538
1539- impl < ' a > DisplayEnum < ' a > {
1539+ impl < ' clean > DisplayEnum < ' clean > {
15401540 fn render_into < W : fmt:: Write > (
15411541 self ,
15421542 cx : & Context < ' _ > ,
15431543 it : & clean:: Item ,
15441544 is_type_alias : bool ,
15451545 w : & mut W ,
15461546 ) -> fmt:: Result {
1547- let variants_count = self . variants . iter ( ) . filter ( |i| !i. is_stripped ( ) ) . count ( ) ;
1547+ let non_stripped_variant_count = self . variants . iter ( ) . filter ( |i| !i. is_stripped ( ) ) . count ( ) ;
15481548 let variants_len = self . variants . len ( ) ;
1549- let has_stripped_entries = variants_len != variants_count ;
1549+ let has_stripped_entries = variants_len != non_stripped_variant_count ;
15501550
15511551 wrap_item ( w, |w| {
1552- if !is_type_alias {
1553- render_attributes_in_code ( w, it, cx) ;
1554- } else {
1555- // For now we only render `repr` attributes for type aliases.
1552+ if is_type_alias {
1553+ // For now the only attributes we render for type aliases are `repr` attributes.
15561554 render_repr_attributes_in_code ( w, cx, self . def_id , ItemType :: Enum ) ;
1555+ } else {
1556+ render_attributes_in_code ( w, it, cx) ;
15571557 }
15581558 write ! (
15591559 w,
@@ -1565,7 +1565,7 @@ impl<'a> DisplayEnum<'a> {
15651565 cx,
15661566 Some ( self . generics) ,
15671567 self . variants,
1568- variants_count ,
1568+ non_stripped_variant_count ,
15691569 has_stripped_entries,
15701570 self . is_non_exhaustive,
15711571 self . def_id,
@@ -1574,14 +1574,16 @@ impl<'a> DisplayEnum<'a> {
15741574 } ) ?;
15751575
15761576 let def_id = it. item_id . expect_def_id ( ) ;
1577- let layout_def_id = if !is_type_alias {
1577+ let layout_def_id = if is_type_alias {
1578+ self . def_id
1579+ } else {
15781580 write ! ( w, "{}" , document( cx, it, None , HeadingOffset :: H2 ) ) ?;
1581+ // We don't return the same `DefId` since the layout size of the type alias might be
1582+ // different since we might have more information on the generics.
15791583 def_id
1580- } else {
1581- self . def_id
15821584 } ;
15831585
1584- if variants_count != 0 {
1586+ if non_stripped_variant_count != 0 {
15851587 write ! ( w, "{}" , item_variants( cx, it, self . variants, self . def_id) ) ?;
15861588 }
15871589 write ! (
@@ -2005,11 +2007,11 @@ impl<'a> DisplayStruct<'a> {
20052007 w : & mut W ,
20062008 ) -> fmt:: Result {
20072009 wrap_item ( w, |w| {
2008- if !is_type_alias {
2009- render_attributes_in_code ( w, it, cx) ;
2010- } else {
2011- // For now we only render `repr` attributes for type aliases.
2010+ if is_type_alias {
2011+ // For now the only attributes we render for type aliases are `repr` attributes.
20122012 render_repr_attributes_in_code ( w, cx, self . def_id , ItemType :: Struct ) ;
2013+ } else {
2014+ render_attributes_in_code ( w, it, cx) ;
20132015 }
20142016 write ! (
20152017 w,
0 commit comments