@@ -7,13 +7,13 @@ use rustc_data_structures::fx::FxHashMap;
77use rustc_hir as hir;
88use rustc_hir:: def:: CtorKind ;
99use rustc_hir:: def_id:: DefId ;
10- use rustc_middle:: bug;
1110use rustc_middle:: middle:: stability;
11+ use rustc_middle:: span_bug;
1212use 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:: Variants ;
16+ use rustc_target:: abi:: { Layout , Variants } ;
1717
1818use super :: {
1919 collect_paths_for_type, document, ensure_trailing_slash, item_ty_to_strs, notable_traits_decl,
@@ -1606,6 +1606,15 @@ 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 ) {
1610+ if layout. abi . is_unsized ( ) {
1611+ write ! ( w, "(unsized)" ) ;
1612+ } else {
1613+ let bytes = layout. size . bytes ( ) ;
1614+ write ! ( w, "{size} byte{pl}" , size = bytes, pl = if bytes == 1 { "" } else { "s" } , ) ;
1615+ }
1616+ }
1617+
16091618 if !cx. shared . show_type_layout {
16101619 return ;
16111620 }
@@ -1627,17 +1636,9 @@ fn document_type_layout(w: &mut Buffer, cx: &Context<'_>, ty_def_id: DefId) {
16271636 <a href=\" https://doc.rust-lang.org/reference/type-layout.html\" >“Type Layout”</a> \
16281637 chapter for details on type layout guarantees.</p></div>"
16291638 ) ;
1630- if ty_layout. layout . abi . is_unsized ( ) {
1631- writeln ! ( w, "<p><strong>Size:</strong> (unsized)</p>" ) ;
1632- } else {
1633- let bytes = ty_layout. layout . size . bytes ( ) ;
1634- writeln ! (
1635- w,
1636- "<p><strong>Size:</strong> {size} byte{pl}</p>" ,
1637- size = bytes,
1638- pl = if bytes == 1 { "" } else { "s" } ,
1639- ) ;
1640- }
1639+ w. write_str ( "<p><strong>Size:</strong> " ) ;
1640+ write_size_of_layout ( w, ty_layout. layout ) ;
1641+ writeln ! ( w, "</p>" ) ;
16411642 if let Variants :: Multiple { variants, .. } = & ty_layout. layout . variants {
16421643 if !variants. is_empty ( ) {
16431644 w. write_str (
@@ -1649,23 +1650,14 @@ fn document_type_layout(w: &mut Buffer, cx: &Context<'_>, ty_def_id: DefId) {
16491650 let adt = if let Adt ( adt, _) = ty_layout. ty . kind ( ) {
16501651 adt
16511652 } else {
1652- bug ! ( "not an adt" )
1653+ span_bug ! ( tcx . def_span ( ty_def_id ) , "not an adt" )
16531654 } ;
16541655
16551656 for ( index, layout) in variants. iter_enumerated ( ) {
16561657 let ident = adt. variants [ index] . ident ;
1657- if layout. abi . is_unsized ( ) {
1658- writeln ! ( w, "<li><code>{name}</code> (unsized)</li>" , name = ident) ;
1659- } else {
1660- let bytes = layout. size . bytes ( ) ;
1661- writeln ! (
1662- w,
1663- "<li><code>{name}</code>: {size} byte{pl}</li>" ,
1664- name = ident,
1665- size = bytes,
1666- pl = if bytes == 1 { "" } else { "s" } ,
1667- ) ;
1668- }
1658+ write ! ( w, "<li><code>{name}</code> " , name = ident) ;
1659+ write_size_of_layout ( w, layout) ;
1660+ writeln ! ( w, "</li>" ) ;
16691661 }
16701662 w. write_str ( "</ul></p>" ) ;
16711663 }
0 commit comments