diff --git a/src/rustc/middle/trans/base.rs b/src/rustc/middle/trans/base.rs index 15f7de84c5f..1c668d30e99 100644 --- a/src/rustc/middle/trans/base.rs +++ b/src/rustc/middle/trans/base.rs @@ -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, diff --git a/src/test/run-pass/issue-2735-2.rs b/src/test/run-pass/issue-2735-2.rs new file mode 100644 index 00000000000..aa9537c7259 --- /dev/null +++ b/src/test/run-pass/issue-2735-2.rs @@ -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); +} diff --git a/src/test/run-pass/issue-2735-3.rs b/src/test/run-pass/issue-2735-3.rs new file mode 100644 index 00000000000..876158d08b2 --- /dev/null +++ b/src/test/run-pass/issue-2735-3.rs @@ -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); +}