//! Visitor for a run-time value with a given layout: Traverse enums, structs and other compound
//! types until we arrive at the leaves, with custom handling for primitive types.
-use rustc::ty::layout::{self, TyLayout, VariantIdx};
+use rustc::mir::interpret::InterpResult;
use rustc::ty;
-use rustc::mir::interpret::{
- InterpResult,
-};
+use rustc::ty::layout::{self, TyLayout, VariantIdx};
-use super::{
- Machine, InterpCx, MPlaceTy, OpTy,
-};
+use super::{InterpCx, MPlaceTy, Machine, OpTy};
// A thing that we can project into, and that has a layout.
// This wouldn't have to depend on `Machine` but with the current type inference,
fn layout(&self) -> TyLayout<'tcx>;
/// Makes this into an `OpTy`.
- fn to_op(
- self,
- ecx: &InterpCx<'mir, 'tcx, M>,
- ) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>>;
+ fn to_op(self, ecx: &InterpCx<'mir, 'tcx, M>) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>>;
/// Creates this from an `MPlaceTy`.
fn from_mem_place(mplace: MPlaceTy<'tcx, M::PointerTag>) -> Self;
) -> InterpResult<'tcx, Self>;
/// Projects to the n-th field.
- fn project_field(
- self,
- ecx: &InterpCx<'mir, 'tcx, M>,
- field: u64,
- ) -> InterpResult<'tcx, Self>;
+ fn project_field(self, ecx: &InterpCx<'mir, 'tcx, M>, field: u64) -> InterpResult<'tcx, Self>;
}
// Operands and memory-places are both values.
}
#[inline(always)]
- fn project_field(
- self,
- ecx: &InterpCx<'mir, 'tcx, M>,
- field: u64,
- ) -> InterpResult<'tcx, Self> {
+ fn project_field(self, ecx: &InterpCx<'mir, 'tcx, M>, field: u64) -> InterpResult<'tcx, Self> {
ecx.operand_field(self, field)
}
}
}
#[inline(always)]
- fn project_field(
- self,
- ecx: &InterpCx<'mir, 'tcx, M>,
- field: u64,
- ) -> InterpResult<'tcx, Self> {
+ fn project_field(self, ecx: &InterpCx<'mir, 'tcx, M>, field: u64) -> InterpResult<'tcx, Self> {
ecx.mplace_field(self, field)
}
}
match v.layout().ty.kind {
ty::Dynamic(..) => {
// immediate trait objects are not a thing
- let dest = v.to_op(self.ecx())?.assert_mem_place();
+ let dest = v.to_op(self.ecx())?.assert_mem_place(self.ecx());
let inner = self.ecx().unpack_dyn_trait(dest)?.1;
trace!("walk_value: dyn object layout: {:#?}", inner.layout);
// recurse with the inner type
},
layout::FieldPlacement::Array { .. } => {
// Let's get an mplace first.
- let mplace = if v.layout().is_zst() {
- // it's a ZST, the memory content cannot matter
- MPlaceTy::dangling(v.layout(), self.ecx())
- } else {
- // non-ZST array/slice/str cannot be immediate
- v.to_op(self.ecx())?.assert_mem_place()
- };
+ let mplace = v.to_op(self.ecx())?.assert_mem_place(self.ecx());
// Now we can go over all the fields.
let iter = self.ecx().mplace_array_fields(mplace)?
.map(|f| f.and_then(|f| {
}
make_value_visitor!(ValueVisitor,);
-make_value_visitor!(MutValueVisitor,mut);
+make_value_visitor!(MutValueVisitor, mut);