@@ -7,6 +7,7 @@ use rustc_hir as hir;
7
7
use rustc_hir:: def:: CtorKind ;
8
8
use rustc_hir:: def_id:: DefId ;
9
9
use rustc_middle:: middle:: stability;
10
+ use rustc_middle:: ty:: layout:: LayoutError ;
10
11
use rustc_middle:: ty:: TyCtxt ;
11
12
use rustc_span:: hygiene:: MacroKind ;
12
13
use rustc_span:: symbol:: { kw, sym, Symbol } ;
@@ -1540,13 +1541,14 @@ fn document_type_layout(w: &mut Buffer, cx: &Context<'_>, ty_def_id: DefId) {
1540
1541
return ;
1541
1542
}
1542
1543
1544
+ writeln ! ( w, "<h2 class=\" small-section-header\" >Layout</h2>" ) ;
1545
+ writeln ! ( w, "<div class=\" docblock\" >" ) ;
1546
+
1543
1547
let tcx = cx. tcx ( ) ;
1544
1548
let param_env = tcx. param_env ( ty_def_id) ;
1545
1549
let ty = tcx. type_of ( ty_def_id) ;
1546
1550
match tcx. layout_of ( param_env. and ( ty) ) {
1547
1551
Ok ( ty_layout) => {
1548
- writeln ! ( w, "<h2 class=\" small-section-header\" >Layout</h2>" ) ;
1549
- writeln ! ( w, "<div class=\" docblock\" >" ) ;
1550
1552
writeln ! (
1551
1553
w,
1552
1554
"<div class=\" warning\" ><p><strong>Note:</strong> Most layout information is \
@@ -1567,11 +1569,28 @@ fn document_type_layout(w: &mut Buffer, cx: &Context<'_>, ty_def_id: DefId) {
1567
1569
pl = if bytes == 1 { "" } else { "s" } ,
1568
1570
) ;
1569
1571
}
1570
- writeln ! ( w, "</div>" ) ;
1571
1572
}
1572
- // Layout errors can occur with valid code, e.g. if you try to get the layout
1573
- // of a generic type such as `Vec<T>`. In case of a layout error, we just
1574
- // don't show any layout information.
1575
- Err ( _) => { }
1573
+ // This kind of layout error can occur with valid code, e.g. if you try to
1574
+ // get the layout of a generic type such as `Vec<T>`.
1575
+ Err ( LayoutError :: Unknown ( _) ) => {
1576
+ writeln ! (
1577
+ w,
1578
+ "<p><strong>Note:</strong> Unable to compute type layout, \
1579
+ possibly due to this type having generic parameters. \
1580
+ Layout can only be computed for concrete, fully-instantiated types.</p>"
1581
+ ) ;
1582
+ }
1583
+ // This kind of error probably can't happen with valid code, but we don't
1584
+ // want to panic and prevent the docs from building, so we just let the
1585
+ // user know that we couldn't compute the layout.
1586
+ Err ( LayoutError :: SizeOverflow ( _) ) => {
1587
+ writeln ! (
1588
+ w,
1589
+ "<p><strong>Note:</strong> Encountered an error during type layout; \
1590
+ the type was too big.</p>"
1591
+ ) ;
1592
+ }
1576
1593
}
1594
+
1595
+ writeln ! ( w, "</div>" ) ;
1577
1596
}
0 commit comments