Skip to content

Commit

Permalink
Fix argument indices in MIR for closures.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
solson committed Dec 30, 2015
1 parent 6e2a64b commit b652774
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/librustc_mir/build/mod.rs
Expand Up @@ -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 });

Expand All @@ -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,
Expand Down

0 comments on commit b652774

Please sign in to comment.