@@ -1457,26 +1457,23 @@ impl<'a, 'cx: 'a> ItemUnion<'a, 'cx> {
1457
1457
ty. print ( self . cx )
1458
1458
}
1459
1459
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
+ } )
1470
1471
}
1471
1472
1472
1473
fn render_attributes_in_pre ( & self ) -> impl fmt:: Display {
1473
1474
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.
1480
1477
if let Some ( repr) = clean:: repr_attributes (
1481
1478
self . cx . tcx ( ) ,
1482
1479
self . cx . cache ( ) ,
@@ -1485,6 +1482,10 @@ impl<'a, 'cx: 'a> ItemUnion<'a, 'cx> {
1485
1482
) {
1486
1483
writeln ! ( f, "{repr}" ) ?;
1487
1484
} ;
1485
+ } else {
1486
+ for a in self . it . attributes_and_repr ( self . cx . tcx ( ) , self . cx . cache ( ) , false ) {
1487
+ writeln ! ( f, "{a}" ) ?;
1488
+ }
1488
1489
}
1489
1490
Ok ( ( ) )
1490
1491
} )
@@ -1501,8 +1502,7 @@ fn item_union(cx: &Context<'_>, it: &clean::Item, s: &clean::Union) -> impl fmt:
1501
1502
is_type_alias : false ,
1502
1503
def_id : it. def_id ( ) . unwrap ( ) ,
1503
1504
}
1504
- . render_into ( w)
1505
- . unwrap ( ) ;
1505
+ . render_into ( w) ?;
1506
1506
Ok ( ( ) )
1507
1507
} )
1508
1508
}
@@ -1529,31 +1529,31 @@ fn print_tuple_struct_fields(cx: &Context<'_>, s: &[clean::Item]) -> impl Displa
1529
1529
} )
1530
1530
}
1531
1531
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 ,
1535
1535
is_non_exhaustive : bool ,
1536
1536
def_id : DefId ,
1537
1537
}
1538
1538
1539
- impl < ' a > DisplayEnum < ' a > {
1539
+ impl < ' clean > DisplayEnum < ' clean > {
1540
1540
fn render_into < W : fmt:: Write > (
1541
1541
self ,
1542
1542
cx : & Context < ' _ > ,
1543
1543
it : & clean:: Item ,
1544
1544
is_type_alias : bool ,
1545
1545
w : & mut W ,
1546
1546
) -> 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 ( ) ;
1548
1548
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 ;
1550
1550
1551
1551
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.
1556
1554
render_repr_attributes_in_code ( w, cx, self . def_id , ItemType :: Enum ) ;
1555
+ } else {
1556
+ render_attributes_in_code ( w, it, cx) ;
1557
1557
}
1558
1558
write ! (
1559
1559
w,
@@ -1565,7 +1565,7 @@ impl<'a> DisplayEnum<'a> {
1565
1565
cx,
1566
1566
Some ( self . generics) ,
1567
1567
self . variants,
1568
- variants_count ,
1568
+ non_stripped_variant_count ,
1569
1569
has_stripped_entries,
1570
1570
self . is_non_exhaustive,
1571
1571
self . def_id,
@@ -1574,14 +1574,16 @@ impl<'a> DisplayEnum<'a> {
1574
1574
} ) ?;
1575
1575
1576
1576
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 {
1578
1580
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.
1579
1583
def_id
1580
- } else {
1581
- self . def_id
1582
1584
} ;
1583
1585
1584
- if variants_count != 0 {
1586
+ if non_stripped_variant_count != 0 {
1585
1587
write ! ( w, "{}" , item_variants( cx, it, self . variants, self . def_id) ) ?;
1586
1588
}
1587
1589
write ! (
@@ -2005,11 +2007,11 @@ impl<'a> DisplayStruct<'a> {
2005
2007
w : & mut W ,
2006
2008
) -> fmt:: Result {
2007
2009
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.
2012
2012
render_repr_attributes_in_code ( w, cx, self . def_id , ItemType :: Struct ) ;
2013
+ } else {
2014
+ render_attributes_in_code ( w, it, cx) ;
2013
2015
}
2014
2016
write ! (
2015
2017
w,
0 commit comments