]> git.lizzy.rs Git - rust.git/commitdiff
Simplify code further
authorMark Simulacrum <mark.simulacrum@gmail.com>
Mon, 2 Jan 2017 21:47:15 +0000 (14:47 -0700)
committerMark Simulacrum <mark.simulacrum@gmail.com>
Wed, 4 Jan 2017 18:38:11 +0000 (11:38 -0700)
src/librustc_trans/mir/block.rs
src/librustc_trans/mir/lvalue.rs

index a62c25f2afc453472706f55aadfc0a5a410a8e75..b9e58f79a5141029471342e9e9af86a94223bc34 100644 (file)
@@ -242,20 +242,14 @@ pub fn trans_block(&mut self, bb: mir::BasicBlock,
                     return;
                 }
 
-                let lvalue = self.trans_lvalue(&bcx, location);
+                let mut lvalue = self.trans_lvalue(&bcx, location);
                 let drop_fn = glue::get_drop_glue(bcx.ccx, ty);
                 let drop_ty = glue::get_drop_glue_type(bcx.ccx.shared(), ty);
-                let ptr = if bcx.ccx.shared().type_is_sized(ty) {
-                    let value = if drop_ty != ty {
-                        bcx.pointercast(lvalue.llval, type_of::type_of(bcx.ccx, drop_ty).ptr_to())
-                    } else {
-                        lvalue.llval
-                    };
-                    LvalueRef::new_sized_ty(value, ty)
-                } else {
-                    LvalueRef::new_unsized_ty(lvalue.llval, lvalue.llextra, ty)
-                };
-                let args = &[ptr.llval, ptr.llextra][..1 + ptr.has_extra() as usize];
+                if bcx.ccx.shared().type_is_sized(ty) && drop_ty != ty {
+                    lvalue.llval = bcx.pointercast(
+                        lvalue.llval, type_of::type_of(bcx.ccx, drop_ty).ptr_to());
+                }
+                let args = &[lvalue.llval, lvalue.llextra][..1 + lvalue.has_extra() as usize];
                 if let Some(unwind) = unwind {
                     bcx.invoke(
                         drop_fn,
index a538a16dc95cbd42578311f0ec4998d1c4de5e25..bd6e70639bba540e4396742fdd5187ea5fc0bedf 100644 (file)
@@ -50,13 +50,6 @@ pub fn new_sized_ty(llval: ValueRef, ty: Ty<'tcx>) -> LvalueRef<'tcx> {
         LvalueRef::new_sized(llval, LvalueTy::from_ty(ty))
     }
 
-    pub fn new_unsized(llval: ValueRef, llextra: ValueRef, ty: LvalueTy<'tcx>) -> LvalueRef<'tcx> {
-        LvalueRef {
-            llval: llval,
-            llextra: llextra,
-            ty: ty,
-        }
-    }
     pub fn new_unsized_ty(llval: ValueRef, llextra: ValueRef, ty: Ty<'tcx>) -> LvalueRef<'tcx> {
         LvalueRef {
             llval: llval,
@@ -81,7 +74,7 @@ pub fn has_extra(&self) -> bool {
         !self.llextra.is_null()
     }
 
-    pub fn struct_field_ptr(
+    fn struct_field_ptr(
         self,
         bcx: &Builder<'a, 'tcx>,
         st: &layout::Struct,
@@ -298,14 +291,12 @@ pub fn trans_lvalue(&mut self,
                 let (llprojected, llextra) = match projection.elem {
                     mir::ProjectionElem::Deref => bug!(),
                     mir::ProjectionElem::Field(ref field, _) => {
-                        let is_sized = self.ccx.shared().type_is_sized(projected_ty.to_ty(tcx));
-                        let base = if is_sized {
-                            LvalueRef::new_sized(tr_base.llval, tr_base.ty)
+                        let llextra = if self.ccx.shared().type_is_sized(projected_ty.to_ty(tcx)) {
+                            ptr::null_mut()
                         } else {
-                            LvalueRef::new_unsized(tr_base.llval, tr_base.llextra, tr_base.ty)
+                            tr_base.llextra
                         };
-                        let llprojected = base.trans_field_ptr(bcx, field.index());
-                        (llprojected, base.llextra)
+                        (tr_base.trans_field_ptr(bcx, field.index()), llextra)
                     }
                     mir::ProjectionElem::Index(ref index) => {
                         let index = self.trans_operand(bcx, index);