@@ -13,7 +13,7 @@ use rustc_middle::ty::layout::LayoutError;
1313use rustc_middle:: ty:: { Adt , TyCtxt } ;
1414use rustc_span:: hygiene:: MacroKind ;
1515use rustc_span:: symbol:: { kw, sym, Symbol } ;
16- use rustc_target:: abi:: { Layout , Variants } ;
16+ use rustc_target:: abi:: { Layout , Primitive , Variants } ;
1717
1818use super :: {
1919 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) {
16061606}
16071607
16081608fn 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 ) {
16101610 if layout. abi . is_unsized ( ) {
16111611 write ! ( w, "(unsized)" ) ;
16121612 } else {
1613- let bytes = layout. size . bytes ( ) ;
1613+ let bytes = layout. size . bytes ( ) - tag_size ;
16141614 write ! ( w, "{size} byte{pl}" , size = bytes, pl = if bytes == 1 { "" } else { "s" } , ) ;
16151615 }
16161616 }
@@ -1637,9 +1637,9 @@ fn document_type_layout(w: &mut Buffer, cx: &Context<'_>, ty_def_id: DefId) {
16371637 chapter for details on type layout guarantees.</p></div>"
16381638 ) ;
16391639 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 ) ;
16411641 writeln ! ( w, "</p>" ) ;
1642- if let Variants :: Multiple { variants, .. } = & ty_layout. layout . variants {
1642+ if let Variants :: Multiple { variants, tag , .. } = & ty_layout. layout . variants {
16431643 if !variants. is_empty ( ) {
16441644 w. write_str (
16451645 "<p>\
@@ -1653,10 +1653,16 @@ fn document_type_layout(w: &mut Buffer, cx: &Context<'_>, ty_def_id: DefId) {
16531653 span_bug ! ( tcx. def_span( ty_def_id) , "not an adt" )
16541654 } ;
16551655
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+
16561662 for ( index, layout) in variants. iter_enumerated ( ) {
16571663 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 ) ;
16601666 writeln ! ( w, "</li>" ) ;
16611667 }
16621668 w. write_str ( "</ul></p>" ) ;
0 commit comments