@@ -59,25 +59,18 @@ impl<'a,'tcx> Builder<'a,'tcx> {
5959 let arg = unpack ! ( block = this. as_operand( block, arg) ) ;
6060 block. and ( Rvalue :: UnaryOp ( op, arg) )
6161 }
62- ExprKind :: Box { value } => {
62+ ExprKind :: Box { value, value_extents } => {
6363 let value = this. hir . mirror ( value) ;
6464 let result = this. temp ( expr. ty ) ;
65-
6665 // to start, malloc some memory of suitable type (thus far, uninitialized):
67- let rvalue = Rvalue :: Box ( value. ty ) ;
68- this. cfg . push_assign ( block, expr_span, & result, rvalue) ;
69-
70- // schedule a shallow free of that memory, lest we unwind:
71- let extent = this. extent_of_innermost_scope ( ) ;
72- this. schedule_drop ( expr_span, extent, DropKind :: Free , & result, value. ty ) ;
73-
74- // initialize the box contents:
75- let contents = result. clone ( ) . deref ( ) ;
76- unpack ! ( block = this. into( & contents, block, value) ) ;
77-
78- // now that the result is fully initialized, cancel the drop
79- // by "using" the result (which is linear):
80- block. and ( Rvalue :: Use ( Operand :: Consume ( result) ) )
66+ this. cfg . push_assign ( block, expr_span, & result, Rvalue :: Box ( value. ty ) ) ;
67+ this. in_scope ( value_extents, block, |this| {
68+ // schedule a shallow free of that memory, lest we unwind:
69+ this. schedule_box_free ( expr_span, value_extents, & result, value. ty ) ;
70+ // initialize the box contents:
71+ unpack ! ( block = this. into( & result. clone( ) . deref( ) , block, value) ) ;
72+ block. and ( Rvalue :: Use ( Operand :: Consume ( result) ) )
73+ } )
8174 }
8275 ExprKind :: Cast { source } => {
8376 let source = unpack ! ( block = this. as_operand( block, source) ) ;
0 commit comments