Skip to content

Commit ca328e1

Browse files
Simplify code further
1 parent c3fe259 commit ca328e1

File tree

2 files changed

+11
-26
lines changed

2 files changed

+11
-26
lines changed

src/librustc_trans/mir/block.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -242,20 +242,14 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
242242
return;
243243
}
244244

245-
let lvalue = self.trans_lvalue(&bcx, location);
245+
let mut lvalue = self.trans_lvalue(&bcx, location);
246246
let drop_fn = glue::get_drop_glue(bcx.ccx, ty);
247247
let drop_ty = glue::get_drop_glue_type(bcx.ccx.shared(), ty);
248-
let ptr = if bcx.ccx.shared().type_is_sized(ty) {
249-
let value = if drop_ty != ty {
250-
bcx.pointercast(lvalue.llval, type_of::type_of(bcx.ccx, drop_ty).ptr_to())
251-
} else {
252-
lvalue.llval
253-
};
254-
LvalueRef::new_sized_ty(value, ty)
255-
} else {
256-
LvalueRef::new_unsized_ty(lvalue.llval, lvalue.llextra, ty)
257-
};
258-
let args = &[ptr.llval, ptr.llextra][..1 + ptr.has_extra() as usize];
248+
if bcx.ccx.shared().type_is_sized(ty) && drop_ty != ty {
249+
lvalue.llval = bcx.pointercast(
250+
lvalue.llval, type_of::type_of(bcx.ccx, drop_ty).ptr_to());
251+
}
252+
let args = &[lvalue.llval, lvalue.llextra][..1 + lvalue.has_extra() as usize];
259253
if let Some(unwind) = unwind {
260254
bcx.invoke(
261255
drop_fn,

src/librustc_trans/mir/lvalue.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,6 @@ impl<'a, 'tcx> LvalueRef<'tcx> {
5050
LvalueRef::new_sized(llval, LvalueTy::from_ty(ty))
5151
}
5252

53-
pub fn new_unsized(llval: ValueRef, llextra: ValueRef, ty: LvalueTy<'tcx>) -> LvalueRef<'tcx> {
54-
LvalueRef {
55-
llval: llval,
56-
llextra: llextra,
57-
ty: ty,
58-
}
59-
}
6053
pub fn new_unsized_ty(llval: ValueRef, llextra: ValueRef, ty: Ty<'tcx>) -> LvalueRef<'tcx> {
6154
LvalueRef {
6255
llval: llval,
@@ -81,7 +74,7 @@ impl<'a, 'tcx> LvalueRef<'tcx> {
8174
!self.llextra.is_null()
8275
}
8376

84-
pub fn struct_field_ptr(
77+
fn struct_field_ptr(
8578
self,
8679
bcx: &Builder<'a, 'tcx>,
8780
st: &layout::Struct,
@@ -298,14 +291,12 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
298291
let (llprojected, llextra) = match projection.elem {
299292
mir::ProjectionElem::Deref => bug!(),
300293
mir::ProjectionElem::Field(ref field, _) => {
301-
let is_sized = self.ccx.shared().type_is_sized(projected_ty.to_ty(tcx));
302-
let base = if is_sized {
303-
LvalueRef::new_sized(tr_base.llval, tr_base.ty)
294+
let llextra = if self.ccx.shared().type_is_sized(projected_ty.to_ty(tcx)) {
295+
ptr::null_mut()
304296
} else {
305-
LvalueRef::new_unsized(tr_base.llval, tr_base.llextra, tr_base.ty)
297+
tr_base.llextra
306298
};
307-
let llprojected = base.trans_field_ptr(bcx, field.index());
308-
(llprojected, base.llextra)
299+
(tr_base.trans_field_ptr(bcx, field.index()), llextra)
309300
}
310301
mir::ProjectionElem::Index(ref index) => {
311302
let index = self.trans_operand(bcx, index);

0 commit comments

Comments
 (0)