move some variables closer to their use site.

This commit is contained in:
Oliver Schneider 2017-02-10 14:50:24 +01:00
parent 2e185485b3
commit 31f3aabdd4

View File

@ -168,11 +168,6 @@ pub fn lvalue_field(
field_ty: Ty<'tcx>,
) -> EvalResult<'tcx, Lvalue<'tcx>> {
let base_layout = self.type_layout(base_ty)?;
// FIXME(solson)
let base = self.force_allocation(base)?;
let (base_ptr, base_extra) = base.to_ptr_and_extra();
let field_ty = self.monomorphize(field_ty, self.substs());
use rustc::ty::layout::Layout::*;
let (offset, packed) = match *base_layout {
@ -181,6 +176,7 @@ pub fn lvalue_field(
},
General { ref variants, .. } => {
let (_, base_extra) = base.to_ptr_and_extra();
if let LvalueExtra::DowncastVariant(variant_idx) = base_extra {
// +1 for the discriminant, which is field 0
(variants[variant_idx].offsets[field + 1], variants[variant_idx].packed)
@ -210,6 +206,10 @@ pub fn lvalue_field(
_ => bug!("field access on non-product type: {:?}", base_layout),
};
// FIXME(solson)
let base = self.force_allocation(base)?;
let (base_ptr, base_extra) = base.to_ptr_and_extra();
let offset = match base_extra {
LvalueExtra::Vtable(tab) => {
let (_, align) = self.size_and_align_of_dst(base_ty, Value::ByValPair(PrimVal::Ptr(base_ptr), PrimVal::Ptr(tab)))?;
@ -220,6 +220,8 @@ pub fn lvalue_field(
let ptr = base_ptr.offset(offset);
let field_ty = self.monomorphize(field_ty, self.substs());
if packed {
let size = self.type_size(field_ty)?.expect("packed struct must be sized");
self.memory.mark_packed(ptr, size);