Skip to content

Commit 6a9c9b0

Browse files
committed
ty::layout: implement layout_of automatically as a default method.
1 parent b710c0d commit 6a9c9b0

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/common.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use rustc_index::vec::IndexVec;
2+
use rustc_middle::ty::layout::LayoutError;
23
use rustc_middle::ty::SymbolName;
34
use rustc_target::abi::call::FnAbi;
45
use rustc_target::abi::{Integer, Primitive};
@@ -259,8 +260,9 @@ pub(crate) struct FunctionCx<'m, 'clif, 'tcx: 'm> {
259260
impl<'tcx> LayoutOf<'tcx> for FunctionCx<'_, '_, 'tcx> {
260261
type LayoutOfResult = TyAndLayout<'tcx>;
261262

262-
fn layout_of(&self, ty: Ty<'tcx>) -> TyAndLayout<'tcx> {
263-
RevealAllLayoutCx(self.tcx).layout_of(ty)
263+
#[inline]
264+
fn handle_layout_err(&self, err: LayoutError<'tcx>, span: Span, ty: Ty<'tcx>) -> ! {
265+
RevealAllLayoutCx(self.tcx).handle_layout_err(err, span, ty)
264266
}
265267
}
266268

@@ -366,15 +368,13 @@ pub(crate) struct RevealAllLayoutCx<'tcx>(pub(crate) TyCtxt<'tcx>);
366368
impl<'tcx> LayoutOf<'tcx> for RevealAllLayoutCx<'tcx> {
367369
type LayoutOfResult = TyAndLayout<'tcx>;
368370

369-
fn layout_of(&self, ty: Ty<'tcx>) -> TyAndLayout<'tcx> {
370-
assert!(!ty.still_further_specializable());
371-
self.0.layout_of(ParamEnv::reveal_all().and(&ty)).unwrap_or_else(|e| {
372-
if let layout::LayoutError::SizeOverflow(_) = e {
373-
self.0.sess.fatal(&e.to_string())
374-
} else {
375-
bug!("failed to get layout for `{}`: {}", ty, e)
376-
}
377-
})
371+
#[inline]
372+
fn handle_layout_err(&self, err: LayoutError<'tcx>, span: Span, ty: Ty<'tcx>) -> ! {
373+
if let layout::LayoutError::SizeOverflow(_) = err {
374+
self.0.sess.span_fatal(span, &err.to_string())
375+
} else {
376+
span_bug!(span, "failed to get layout for `{}`: {}", ty, err)
377+
}
378378
}
379379
}
380380

0 commit comments

Comments
 (0)