Skip to content

Commit b652774

Browse files
committed
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.
1 parent 6e2a64b commit b652774

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/librustc_mir/build/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
139139
{
140140
self.in_scope(argument_extent, block, |this| {
141141
let arg_decls = {
142+
let num_implicit_args = implicit_arguments.len();
142143
let implicit_arg_decls = implicit_arguments.into_iter()
143144
.map(|ty| ArgDecl { ty: ty });
144145

@@ -149,7 +150,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
149150
.into_iter()
150151
.enumerate()
151152
.map(|(index, (ty, pattern))| {
152-
let lvalue = Lvalue::Arg(index as u32);
153+
let lvalue = Lvalue::Arg((num_implicit_args + index) as u32);
153154
let pattern = this.hir.irrefutable_pat(pattern);
154155
unpack!(block = this.lvalue_into_pattern(block,
155156
argument_extent,

0 commit comments

Comments
 (0)