@@ -13,7 +13,7 @@ use rustc_middle::ty::layout::LayoutError;
13
13
use rustc_middle:: ty:: { Adt , TyCtxt } ;
14
14
use rustc_span:: hygiene:: MacroKind ;
15
15
use rustc_span:: symbol:: { kw, sym, Symbol } ;
16
- use rustc_target:: abi:: { Layout , Variants } ;
16
+ use rustc_target:: abi:: { Layout , Primitive , Variants } ;
17
17
18
18
use super :: {
19
19
collect_paths_for_type, document, ensure_trailing_slash, item_ty_to_strs, notable_traits_decl,
@@ -1606,11 +1606,11 @@ fn document_non_exhaustive(w: &mut Buffer, item: &clean::Item) {
1606
1606
}
1607
1607
1608
1608
fn document_type_layout ( w : & mut Buffer , cx : & Context < ' _ > , ty_def_id : DefId ) {
1609
- fn write_size_of_layout ( w : & mut Buffer , layout : & Layout ) {
1609
+ fn write_size_of_layout ( w : & mut Buffer , layout : & Layout , tag_size : u64 ) {
1610
1610
if layout. abi . is_unsized ( ) {
1611
1611
write ! ( w, "(unsized)" ) ;
1612
1612
} else {
1613
- let bytes = layout. size . bytes ( ) ;
1613
+ let bytes = layout. size . bytes ( ) - tag_size ;
1614
1614
write ! ( w, "{size} byte{pl}" , size = bytes, pl = if bytes == 1 { "" } else { "s" } , ) ;
1615
1615
}
1616
1616
}
@@ -1637,9 +1637,9 @@ fn document_type_layout(w: &mut Buffer, cx: &Context<'_>, ty_def_id: DefId) {
1637
1637
chapter for details on type layout guarantees.</p></div>"
1638
1638
) ;
1639
1639
w. write_str ( "<p><strong>Size:</strong> " ) ;
1640
- write_size_of_layout ( w, ty_layout. layout ) ;
1640
+ write_size_of_layout ( w, ty_layout. layout , 0 ) ;
1641
1641
writeln ! ( w, "</p>" ) ;
1642
- if let Variants :: Multiple { variants, .. } = & ty_layout. layout . variants {
1642
+ if let Variants :: Multiple { variants, tag , .. } = & ty_layout. layout . variants {
1643
1643
if !variants. is_empty ( ) {
1644
1644
w. write_str (
1645
1645
"<p>\
@@ -1653,10 +1653,16 @@ fn document_type_layout(w: &mut Buffer, cx: &Context<'_>, ty_def_id: DefId) {
1653
1653
span_bug ! ( tcx. def_span( ty_def_id) , "not an adt" )
1654
1654
} ;
1655
1655
1656
+ let tag_size = if let Primitive :: Int ( i, _) = tag. value {
1657
+ i. size ( ) . bytes ( )
1658
+ } else {
1659
+ span_bug ! ( tcx. def_span( ty_def_id) , "tag is not int" )
1660
+ } ;
1661
+
1656
1662
for ( index, layout) in variants. iter_enumerated ( ) {
1657
1663
let ident = adt. variants [ index] . ident ;
1658
- write ! ( w, "<li><code>{name}</code> " , name = ident) ;
1659
- write_size_of_layout ( w, layout) ;
1664
+ write ! ( w, "<li><code>{name}</code>: " , name = ident) ;
1665
+ write_size_of_layout ( w, layout, tag_size ) ;
1660
1666
writeln ! ( w, "</li>" ) ;
1661
1667
}
1662
1668
w. write_str ( "</ul></p>" ) ;
0 commit comments