@@ -640,6 +640,16 @@ fn incr_all_refcnts(@block_ctxt cx,
640
640
ret res( cx, C_nil ( ) ) ;
641
641
}
642
642
643
+ fn drop_slot ( @block_ctxt cx ,
644
+ ValueRef slot,
645
+ @typeck. ty t ) -> result {
646
+ if ( typeck. type_is_structural ( t) ) {
647
+ be drop_ty ( cx, slot, t) ;
648
+ } else {
649
+ be drop_ty ( cx, cx. build . Load ( slot) , t) ;
650
+ }
651
+ }
652
+
643
653
fn drop_ty ( @block_ctxt cx ,
644
654
ValueRef v,
645
655
@typeck. ty t ) -> result {
@@ -812,7 +822,8 @@ impure fn trans_lit(@block_ctxt cx, &ast.lit lit) -> result {
812
822
C_int ( len) ) ) ;
813
823
sub. val = sub. bcx . build . IntToPtr ( sub. val ,
814
824
T_ptr ( T_str ( ) ) ) ;
815
- cx. cleanups += clean ( bind trans_drop_str ( _, sub. val ) ) ;
825
+ find_scope_cx ( cx) . cleanups +=
826
+ clean ( bind trans_drop_str ( _, sub. val ) ) ;
816
827
ret sub;
817
828
}
818
829
}
@@ -1529,13 +1540,18 @@ impure fn trans_stmt(@block_ctxt cx, &ast.stmt s) -> result {
1529
1540
case ( ast. stmt_decl( ?d) ) {
1530
1541
alt ( d. node) {
1531
1542
case ( ast. decl_local( ?local) ) {
1543
+
1544
+ // Make a note to drop this slot on the way out.
1545
+ check ( cx. fcx. lllocals. contains_key( local. id) ) ;
1546
+ auto llptr = cx. fcx. lllocals. get( local. id) ;
1547
+ auto ty = node_ann_type( cx. fcx. ccx, local. ann) ;
1548
+ find_scope_cx( sub. bcx) . cleanups +=
1549
+ clean( bind drop_slot( _, llptr, ty) ) ;
1550
+
1532
1551
alt ( local. init) {
1533
1552
case ( some[ @ast. expr] ( ?e) ) {
1534
- check ( cx. fcx. lllocals. contains_key( local. id) ) ;
1535
- auto llptr = cx. fcx. lllocals. get( local. id) ;
1536
1553
sub = trans_expr( cx, e) ;
1537
- sub = copy_ty( sub. bcx, true, llptr, sub. val,
1538
- typeck. expr_ty( e) ) ;
1554
+ sub = copy_ty( sub. bcx, true, llptr, sub. val, ty) ;
1539
1555
}
1540
1556
case ( _) { /* fall through */ }
1541
1557
}
@@ -1658,7 +1674,7 @@ impure fn trans_block(@block_ctxt cx, &ast.block b) -> result {
1658
1674
}
1659
1675
}
1660
1676
1661
- bcx = trans_block_cleanups ( bcx, bcx) ;
1677
+ bcx = trans_block_cleanups ( bcx, find_scope_cx ( bcx) ) ;
1662
1678
ret res( bcx, r. val ) ;
1663
1679
}
1664
1680
0 commit comments