From 31f3aabdd46e93bdbe88c08c1e62d5530dab182f Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Fri, 10 Feb 2017 14:50:24 +0100 Subject: [PATCH] move some variables closer to their use site. --- src/lvalue.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/lvalue.rs b/src/lvalue.rs index 5ac5ad78b8a..859ed32405c 100644 --- a/src/lvalue.rs +++ b/src/lvalue.rs @@ -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);