@@ -846,6 +846,7 @@ fn item_union(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::Uni
846
846
} ) ;
847
847
848
848
document ( w, cx, it, None ) ;
849
+
849
850
let mut fields = s
850
851
. fields
851
852
. iter ( )
@@ -880,7 +881,9 @@ fn item_union(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::Uni
880
881
document ( w, cx, field, Some ( it) ) ;
881
882
}
882
883
}
883
- render_assoc_items ( w, cx, it, it. def_id . expect_real ( ) , AssocItemRender :: All )
884
+ let def_id = it. def_id . expect_real ( ) ;
885
+ render_assoc_items ( w, cx, it, def_id, AssocItemRender :: All ) ;
886
+ document_ty_layout ( w, cx, def_id) ;
884
887
}
885
888
886
889
fn item_enum ( w : & mut Buffer , cx : & Context < ' _ > , it : & clean:: Item , e : & clean:: Enum ) {
@@ -940,6 +943,7 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum
940
943
} ) ;
941
944
942
945
document ( w, cx, it, None ) ;
946
+
943
947
if !e. variants . is_empty ( ) {
944
948
write ! (
945
949
w,
@@ -1014,7 +1018,9 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum
1014
1018
render_stability_since ( w, variant, it, cx. tcx ( ) ) ;
1015
1019
}
1016
1020
}
1017
- render_assoc_items ( w, cx, it, it. def_id . expect_real ( ) , AssocItemRender :: All )
1021
+ let def_id = it. def_id . expect_real ( ) ;
1022
+ render_assoc_items ( w, cx, it, def_id, AssocItemRender :: All ) ;
1023
+ document_ty_layout ( w, cx, def_id) ;
1018
1024
}
1019
1025
1020
1026
fn item_macro ( w : & mut Buffer , cx : & Context < ' _ > , it : & clean:: Item , t : & clean:: Macro ) {
@@ -1114,6 +1120,7 @@ fn item_struct(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::St
1114
1120
} ) ;
1115
1121
1116
1122
document ( w, cx, it, None ) ;
1123
+
1117
1124
let mut fields = s
1118
1125
. fields
1119
1126
. iter ( )
@@ -1152,7 +1159,9 @@ fn item_struct(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::St
1152
1159
}
1153
1160
}
1154
1161
}
1155
- render_assoc_items ( w, cx, it, it. def_id . expect_real ( ) , AssocItemRender :: All )
1162
+ let def_id = it. def_id . expect_real ( ) ;
1163
+ render_assoc_items ( w, cx, it, def_id, AssocItemRender :: All ) ;
1164
+ document_ty_layout ( w, cx, def_id) ;
1156
1165
}
1157
1166
1158
1167
fn item_static ( w : & mut Buffer , cx : & Context < ' _ > , it : & clean:: Item , s : & clean:: Static ) {
@@ -1522,3 +1531,27 @@ fn document_non_exhaustive(w: &mut Buffer, item: &clean::Item) {
1522
1531
w. write_str ( "</div></details>" ) ;
1523
1532
}
1524
1533
}
1534
+
1535
+ fn document_ty_layout ( w : & mut Buffer , cx : & Context < ' _ > , ty_def_id : DefId ) {
1536
+ let param_env = cx. tcx ( ) . param_env ( ty_def_id) ;
1537
+ let ty = cx. tcx ( ) . type_of ( ty_def_id) ;
1538
+ match cx. tcx ( ) . layout_of ( param_env. and ( ty) ) {
1539
+ Ok ( ty_layout) => {
1540
+ writeln ! ( w, r#"<h2 class="small-section-header">Layout</h2>"# ) ;
1541
+ writeln ! ( w, "<div>" ) ;
1542
+ if ty_layout. layout . abi . is_unsized ( ) {
1543
+ writeln ! ( w, "<strong>Sized:</strong> (unsized)" ) ;
1544
+ } else {
1545
+ writeln ! (
1546
+ w,
1547
+ "<strong>Size:</strong> {size} byte{pl}" ,
1548
+ size = ty_layout. layout. size. bytes( ) ,
1549
+ pl = if ty_layout. layout. size. bytes( ) == 1 { "" } else { "s" } ,
1550
+ ) ;
1551
+ }
1552
+ writeln ! ( w, "</div>" ) ;
1553
+ }
1554
+ // FIXME: should we crash instead? or report an error?
1555
+ Err ( _layout_err) => { }
1556
+ }
1557
+ }
0 commit comments