ty::layout: implement layout_of
automatically as a default method.
This commit is contained in:
parent
4ce933f13f
commit
1e02262dcc
8 changed files with 105 additions and 54 deletions
|
@ -8,7 +8,7 @@ use rustc_index::vec::IndexVec;
|
|||
use rustc_macros::HashStable;
|
||||
use rustc_middle::ich::StableHashingContext;
|
||||
use rustc_middle::mir;
|
||||
use rustc_middle::ty::layout::{self, LayoutOf, TyAndLayout};
|
||||
use rustc_middle::ty::layout::{self, LayoutError, LayoutOf, TyAndLayout};
|
||||
use rustc_middle::ty::{
|
||||
self, query::TyCtxtAt, subst::SubstsRef, ParamEnv, Ty, TyCtxt, TypeFoldable,
|
||||
};
|
||||
|
@ -17,9 +17,9 @@ use rustc_span::{Pos, Span};
|
|||
use rustc_target::abi::{Align, HasDataLayout, Size, TargetDataLayout};
|
||||
|
||||
use super::{
|
||||
AllocId, GlobalId, Immediate, InterpResult, MPlaceTy, Machine, MemPlace, MemPlaceMeta, Memory,
|
||||
MemoryKind, Operand, Place, PlaceTy, Pointer, Provenance, Scalar, ScalarMaybeUninit,
|
||||
StackPopJump,
|
||||
AllocId, GlobalId, Immediate, InterpErrorInfo, InterpResult, MPlaceTy, Machine, MemPlace,
|
||||
MemPlaceMeta, Memory, MemoryKind, Operand, Place, PlaceTy, Pointer, Provenance, Scalar,
|
||||
ScalarMaybeUninit, StackPopJump,
|
||||
};
|
||||
use crate::transform::validate::equal_up_to_regions;
|
||||
use crate::util::storage::AlwaysLiveLocals;
|
||||
|
@ -316,10 +316,18 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> LayoutOf<'tcx> for InterpCx<'mir,
|
|||
type LayoutOfResult = InterpResult<'tcx, TyAndLayout<'tcx>>;
|
||||
|
||||
#[inline]
|
||||
fn layout_of(&self, ty: Ty<'tcx>) -> Self::LayoutOfResult {
|
||||
self.tcx
|
||||
.layout_of(self.param_env.and(ty))
|
||||
.map_err(|layout| err_inval!(Layout(layout)).into())
|
||||
fn layout_tcx_at_span(&self) -> Span {
|
||||
self.tcx.span
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn handle_layout_err(
|
||||
&self,
|
||||
err: LayoutError<'tcx>,
|
||||
_: Span,
|
||||
_: Ty<'tcx>,
|
||||
) -> InterpErrorInfo<'tcx> {
|
||||
err_inval!(Layout(err)).into()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -333,8 +333,9 @@ struct ConstPropagator<'mir, 'tcx> {
|
|||
impl<'mir, 'tcx> LayoutOf<'tcx> for ConstPropagator<'mir, 'tcx> {
|
||||
type LayoutOfResult = Result<TyAndLayout<'tcx>, LayoutError<'tcx>>;
|
||||
|
||||
fn layout_of(&self, ty: Ty<'tcx>) -> Self::LayoutOfResult {
|
||||
self.tcx.layout_of(self.param_env.and(ty))
|
||||
#[inline]
|
||||
fn handle_layout_err(&self, err: LayoutError<'tcx>, _: Span, _: Ty<'tcx>) -> LayoutError<'tcx> {
|
||||
err
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue