From b65277496c8848cd6f08b55e8b413096c74b92af Mon Sep 17 00:00:00 2001 From: Scott Olson Date: Tue, 29 Dec 2015 22:55:38 -0600 Subject: [PATCH] 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. --- src/librustc_mir/build/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs index bd94f4e5bf2..7ea9301664f 100644 --- a/src/librustc_mir/build/mod.rs +++ b/src/librustc_mir/build/mod.rs @@ -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,