Skip to content

Commit d0c585c

Browse files
committed
seems like for generators we cannot access the freevars
1 parent 93f53e5 commit d0c585c

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/librustc_mir/interpret/validity.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -559,12 +559,16 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
559559
// generators and closures.
560560
ty::Closure(def_id, _) | ty::Generator(def_id, _, _) => {
561561
if let Some(node_id) = self.tcx.hir.as_local_node_id(def_id) {
562-
let freevar = self.tcx.with_freevars(node_id, |fv| fv[field]);
563-
PathElem::ClosureVar(self.tcx.hir.name(freevar.var_id()))
564-
} else {
565-
// The closure is not local, so we cannot get the name
566-
PathElem::ClosureVar(Symbol::intern(&field.to_string()))
562+
if let Some(freevar) = self.tcx.with_freevars(
563+
node_id,
564+
|fv| fv.get(field).map(|field| *field))
565+
{
566+
return PathElem::ClosureVar(self.tcx.hir.name(freevar.var_id()));
567+
}
567568
}
569+
// The closure is not local, or the freevars don't match up (seen for a generator!),
570+
// so we cannot get the name.
571+
PathElem::ClosureVar(Symbol::intern(&field.to_string()))
568572
}
569573

570574
// tuples

0 commit comments

Comments
 (0)