Fix argument indices in MIR for closures.

Previously, all references to closure arguments went to the argument before the
one they should (e.g. to arg1 when it was supposed to be arg2). This was because
the MIR builder did not account for the implicit arguments that come before the
explicit arguments, and closures have one implicit argument - the struct
containing the captures.
This commit is contained in:
Scott Olson 2015-12-29 22:55:38 -06:00
parent 6e2a64b57a
commit b65277496c

View File

@ -139,6 +139,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
{
self.in_scope(argument_extent, block, |this| {
let arg_decls = {
let num_implicit_args = implicit_arguments.len();
let implicit_arg_decls = implicit_arguments.into_iter()
.map(|ty| ArgDecl { ty: ty });
@ -149,7 +150,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
.into_iter()
.enumerate()
.map(|(index, (ty, pattern))| {
let lvalue = Lvalue::Arg(index as u32);
let lvalue = Lvalue::Arg((num_implicit_args + index) as u32);
let pattern = this.hir.irrefutable_pat(pattern);
unpack!(block = this.lvalue_into_pattern(block,
argument_extent,