Skip to content

Commit

Permalink
auto merge of #10735 : alexcrichton/rust/issue-10734, r=cmr
Browse files Browse the repository at this point in the history
Turns out `with_scope` already translates destructors, so by manually
translating destructors we end up running them all twice (bad).

Closes #10734
  • Loading branch information
bors committed Nov 30, 2013
2 parents 156054f + 7bb166e commit eeaf2e1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/librustc/middle/trans/controlflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub fn trans_if(bcx: @mut Block,
return with_scope(bcx, thn.info(), "if_true_then", |bcx| {
let bcx_out = trans_block(bcx, thn, dest);
debuginfo::clear_source_location(bcx.fcx);
trans_block_cleanups(bcx_out, block_cleanups(bcx))
bcx_out
})
} else {
let mut trans = TransItemVisitor { ccx: bcx.fcx.ccx } ;
Expand All @@ -90,9 +90,9 @@ pub fn trans_if(bcx: @mut Block,
elexpr.info(),
"if_false_then",
|bcx| {
let bcx_out = trans_if_else(bcx, elexpr, dest);
let bcx_out = trans_if_else(bcx, elexpr, dest, false);
debuginfo::clear_source_location(bcx.fcx);
trans_block_cleanups(bcx_out, block_cleanups(bcx))
bcx_out
})
}
// if false { .. }
Expand All @@ -116,7 +116,7 @@ pub fn trans_if(bcx: @mut Block,
let (else_bcx_in, next_bcx) = match els {
Some(elexpr) => {
let else_bcx_in = scope_block(bcx, elexpr.info(), "else");
let else_bcx_out = trans_if_else(else_bcx_in, elexpr, dest);
let else_bcx_out = trans_if_else(else_bcx_in, elexpr, dest, true);
(else_bcx_in, join_blocks(bcx, [then_bcx_out, else_bcx_out]))
}
_ => {
Expand All @@ -138,7 +138,7 @@ pub fn trans_if(bcx: @mut Block,

// trans `else [ if { .. } ... | { .. } ]`
fn trans_if_else(else_bcx_in: @mut Block, elexpr: @ast::Expr,
dest: expr::Dest) -> @mut Block {
dest: expr::Dest, cleanup: bool) -> @mut Block {
let else_bcx_out = match elexpr.node {
ast::ExprIf(_, _, _) => {
let elseif_blk = ast_util::block_from_expr(elexpr);
Expand All @@ -150,8 +150,12 @@ pub fn trans_if(bcx: @mut Block,
// would be nice to have a constraint on ifs
_ => else_bcx_in.tcx().sess.bug("strange alternative in if")
};
debuginfo::clear_source_location(else_bcx_in.fcx);
trans_block_cleanups(else_bcx_out, block_cleanups(else_bcx_in))
if cleanup {
debuginfo::clear_source_location(else_bcx_in.fcx);
trans_block_cleanups(else_bcx_out, block_cleanups(else_bcx_in))
} else {
else_bcx_out
}
}
}

Expand Down
20 changes: 20 additions & 0 deletions src/test/run-pass/issue-10734.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

pub fn main() {
if true {
let _a = ~3;
}
if false {
fail!()
} else {
let _a = ~3;
}
}

0 comments on commit eeaf2e1

Please sign in to comment.