diff --git a/src/librustc_trans/mir/analyze.rs b/src/librustc_trans/mir/analyze.rs index 93ac002f2a98..65581d43f882 100644 --- a/src/librustc_trans/mir/analyze.rs +++ b/src/librustc_trans/mir/analyze.rs @@ -18,6 +18,7 @@ use rustc::mir::repr::TerminatorKind; use rustc::mir::visit::{Visitor, LvalueContext}; use rustc::mir::traversal; use common::{self, Block, BlockAndBuilder}; +use glue; use super::rvalue; pub fn lvalue_temps<'bcx,'tcx>(bcx: Block<'bcx,'tcx>, @@ -138,13 +139,21 @@ impl<'mir, 'bcx, 'tcx> Visitor<'tcx> for TempAnalyzer<'mir, 'bcx, 'tcx> { LvalueContext::Consume => { } LvalueContext::Store | - LvalueContext::Drop | LvalueContext::Inspect | LvalueContext::Borrow { .. } | LvalueContext::Slice { .. } | LvalueContext::Projection => { self.mark_as_lvalue(temp.index()); } + LvalueContext::Drop => { + let ty = self.mir.temp_decls[index as usize].ty; + let ty = self.bcx.monomorphize(&ty); + + // Only need the lvalue if we're actually dropping it. + if glue::type_needs_drop(self.bcx.tcx(), ty) { + self.mark_as_lvalue(index as usize); + } + } } } _ => { diff --git a/src/librustc_trans/mir/block.rs b/src/librustc_trans/mir/block.rs index bdcf3dd8cd41..4591fa285781 100644 --- a/src/librustc_trans/mir/block.rs +++ b/src/librustc_trans/mir/block.rs @@ -196,13 +196,16 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> { } mir::TerminatorKind::Drop { ref location, target, unwind } => { - let lvalue = self.trans_lvalue(&bcx, location); - let ty = lvalue.ty.to_ty(bcx.tcx()); + let ty = mir.lvalue_ty(bcx.tcx(), location).to_ty(bcx.tcx()); + let ty = bcx.monomorphize(&ty); + // Double check for necessity to drop if !glue::type_needs_drop(bcx.tcx(), ty) { funclet_br(self, bcx, target); return; } + + let 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.tcx(), ty); let llvalue = if drop_ty != ty {