@@ -7,13 +7,13 @@ use rustc_data_structures::fx::FxHashMap;
7
7
use rustc_hir as hir;
8
8
use rustc_hir:: def:: CtorKind ;
9
9
use rustc_hir:: def_id:: DefId ;
10
- use rustc_middle:: bug;
11
10
use rustc_middle:: middle:: stability;
11
+ use rustc_middle:: span_bug;
12
12
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:: Variants ;
16
+ use rustc_target:: abi:: { Layout , 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,6 +1606,15 @@ 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 ) {
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
+
1609
1618
if !cx. shared . show_type_layout {
1610
1619
return ;
1611
1620
}
@@ -1627,17 +1636,9 @@ fn document_type_layout(w: &mut Buffer, cx: &Context<'_>, ty_def_id: DefId) {
1627
1636
<a href=\" https://doc.rust-lang.org/reference/type-layout.html\" >“Type Layout”</a> \
1628
1637
chapter for details on type layout guarantees.</p></div>"
1629
1638
) ;
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>" ) ;
1641
1642
if let Variants :: Multiple { variants, .. } = & ty_layout. layout . variants {
1642
1643
if !variants. is_empty ( ) {
1643
1644
w. write_str (
@@ -1649,23 +1650,14 @@ fn document_type_layout(w: &mut Buffer, cx: &Context<'_>, ty_def_id: DefId) {
1649
1650
let adt = if let Adt ( adt, _) = ty_layout. ty . kind ( ) {
1650
1651
adt
1651
1652
} else {
1652
- bug ! ( "not an adt" )
1653
+ span_bug ! ( tcx . def_span ( ty_def_id ) , "not an adt" )
1653
1654
} ;
1654
1655
1655
1656
for ( index, layout) in variants. iter_enumerated ( ) {
1656
1657
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>" ) ;
1669
1661
}
1670
1662
w. write_str ( "</ul></p>" ) ;
1671
1663
}
0 commit comments