Skip to content

Commit eeaf2e1

Browse files
committed
auto merge of #10735 : alexcrichton/rust/issue-10734, r=cmr
Turns out `with_scope` already translates destructors, so by manually translating destructors we end up running them all twice (bad). Closes #10734
2 parents 156054f + 7bb166e commit eeaf2e1

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

src/librustc/middle/trans/controlflow.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ pub fn trans_if(bcx: @mut Block,
7777
return with_scope(bcx, thn.info(), "if_true_then", |bcx| {
7878
let bcx_out = trans_block(bcx, thn, dest);
7979
debuginfo::clear_source_location(bcx.fcx);
80-
trans_block_cleanups(bcx_out, block_cleanups(bcx))
80+
bcx_out
8181
})
8282
} else {
8383
let mut trans = TransItemVisitor { ccx: bcx.fcx.ccx } ;
@@ -90,9 +90,9 @@ pub fn trans_if(bcx: @mut Block,
9090
elexpr.info(),
9191
"if_false_then",
9292
|bcx| {
93-
let bcx_out = trans_if_else(bcx, elexpr, dest);
93+
let bcx_out = trans_if_else(bcx, elexpr, dest, false);
9494
debuginfo::clear_source_location(bcx.fcx);
95-
trans_block_cleanups(bcx_out, block_cleanups(bcx))
95+
bcx_out
9696
})
9797
}
9898
// if false { .. }
@@ -116,7 +116,7 @@ pub fn trans_if(bcx: @mut Block,
116116
let (else_bcx_in, next_bcx) = match els {
117117
Some(elexpr) => {
118118
let else_bcx_in = scope_block(bcx, elexpr.info(), "else");
119-
let else_bcx_out = trans_if_else(else_bcx_in, elexpr, dest);
119+
let else_bcx_out = trans_if_else(else_bcx_in, elexpr, dest, true);
120120
(else_bcx_in, join_blocks(bcx, [then_bcx_out, else_bcx_out]))
121121
}
122122
_ => {
@@ -138,7 +138,7 @@ pub fn trans_if(bcx: @mut Block,
138138

139139
// trans `else [ if { .. } ... | { .. } ]`
140140
fn trans_if_else(else_bcx_in: @mut Block, elexpr: @ast::Expr,
141-
dest: expr::Dest) -> @mut Block {
141+
dest: expr::Dest, cleanup: bool) -> @mut Block {
142142
let else_bcx_out = match elexpr.node {
143143
ast::ExprIf(_, _, _) => {
144144
let elseif_blk = ast_util::block_from_expr(elexpr);
@@ -150,8 +150,12 @@ pub fn trans_if(bcx: @mut Block,
150150
// would be nice to have a constraint on ifs
151151
_ => else_bcx_in.tcx().sess.bug("strange alternative in if")
152152
};
153-
debuginfo::clear_source_location(else_bcx_in.fcx);
154-
trans_block_cleanups(else_bcx_out, block_cleanups(else_bcx_in))
153+
if cleanup {
154+
debuginfo::clear_source_location(else_bcx_in.fcx);
155+
trans_block_cleanups(else_bcx_out, block_cleanups(else_bcx_in))
156+
} else {
157+
else_bcx_out
158+
}
155159
}
156160
}
157161

src/test/run-pass/issue-10734.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
pub fn main() {
12+
if true {
13+
let _a = ~3;
14+
}
15+
if false {
16+
fail!()
17+
} else {
18+
let _a = ~3;
19+
}
20+
}

0 commit comments

Comments
 (0)