Make let _ = e; have the same semantics as e;
The first case was getting treated like a variable binding, meaning that if e had a destructor, it wouldn't run until the end of the enclosing scope. To me it seems less confusing for let _ = e; and e; to work exactly the same way, so now, the destructor for e runs immediately in both cases.
This commit is contained in:
parent
d99ca69cf7
commit
febd7ee239
@ -4206,9 +4206,26 @@ fn build_return(bcx: block) {
|
||||
Br(bcx, bcx.fcx.llreturn);
|
||||
}
|
||||
|
||||
fn ignore_lhs(_bcx: block, local: @ast::local) -> bool {
|
||||
match local.node.pat.node {
|
||||
ast::pat_wild => true, _ => false
|
||||
}
|
||||
}
|
||||
|
||||
fn init_local(bcx: block, local: @ast::local) -> block {
|
||||
let _icx = bcx.insn_ctxt(~"init_local");
|
||||
let ty = node_id_type(bcx, local.node.id);
|
||||
|
||||
if ignore_lhs(bcx, local) {
|
||||
// Handle let _ = e; just like e;
|
||||
match local.node.init {
|
||||
some(init) => {
|
||||
return trans_expr(bcx, init.expr, ignore);
|
||||
}
|
||||
none => { return bcx; }
|
||||
}
|
||||
}
|
||||
|
||||
let llptr = match bcx.fcx.lllocals.find(local.node.id) {
|
||||
some(local_mem(v)) => v,
|
||||
_ => { bcx.tcx().sess.span_bug(local.span,
|
||||
|
14
src/test/run-pass/issue-2735-2.rs
Normal file
14
src/test/run-pass/issue-2735-2.rs
Normal file
@ -0,0 +1,14 @@
|
||||
// This test should behave exactly like issue-2735-3
|
||||
class defer {
|
||||
let b: &mut bool;
|
||||
new(b: &mut bool) {
|
||||
self.b = b;
|
||||
}
|
||||
drop { *(self.b) = true; }
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut dtor_ran = false;
|
||||
let _ = defer(&mut dtor_ran);
|
||||
assert(dtor_ran);
|
||||
}
|
14
src/test/run-pass/issue-2735-3.rs
Normal file
14
src/test/run-pass/issue-2735-3.rs
Normal file
@ -0,0 +1,14 @@
|
||||
// This test should behave exactly like issue-2735-2
|
||||
class defer {
|
||||
let b: &mut bool;
|
||||
new(b: &mut bool) {
|
||||
self.b = b;
|
||||
}
|
||||
drop { *(self.b) = true; }
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut dtor_ran = false;
|
||||
defer(&mut dtor_ran);
|
||||
assert(dtor_ran);
|
||||
}
|
Loading…
Reference in New Issue
Block a user