use pre-existing abi_align method instead of magic formula

This commit is contained in:
Oliver Schneider 2017-02-09 08:50:35 +01:00
parent 1844381ad0
commit 8030800b15

View File

@ -1,6 +1,6 @@
use rustc::hir::def_id::DefId;
use rustc::mir;
use rustc::ty::layout::Size;
use rustc::ty::layout::{Size, Align};
use rustc::ty::subst::Substs;
use rustc::ty::{self, Ty};
use rustc_data_structures::indexed_vec::Idx;
@ -217,8 +217,7 @@ fn eval_lvalue_projection(
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)))?;
// magical formula taken from rustc
(offset.bytes() + (align - 1)) & (-(align as i64) as u64)
offset.abi_align(Align::from_bytes(align, align).unwrap()).bytes()
}
_ => offset.bytes(),
};