1 use rustc::ty::{self, TyCtxt};
4 /// Returns `true` if this place is allowed to be less aligned
5 /// than its containing struct (because it is within a packed
7 pub fn is_disaligned<'a, 'tcx, L>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
9 param_env: ty::ParamEnv<'tcx>,
12 where L: HasLocalDecls<'tcx>
14 debug!("is_disaligned({:?})", place);
15 if !is_within_packed(tcx, local_decls, place) {
16 debug!("is_disaligned({:?}) - not within packed", place);
20 let ty = place.ty(local_decls, tcx).to_ty(tcx);
21 match tcx.layout_raw(param_env.and(ty)) {
22 Ok(layout) if layout.align.abi.bytes() == 1 => {
23 // if the alignment is 1, the type can't be further
25 debug!("is_disaligned({:?}) - align = 1", place);
29 debug!("is_disaligned({:?}) - true", place);
35 fn is_within_packed<'a, 'tcx, L>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
39 where L: HasLocalDecls<'tcx>
41 let mut place = place;
42 while let &Place::Projection(box Projection {
46 // encountered a Deref, which is ABI-aligned
47 ProjectionElem::Deref => break,
48 ProjectionElem::Field(..) => {
49 let ty = base.ty(local_decls, tcx).to_ty(tcx);
51 ty::Adt(def, _) if def.repr.packed() => {