]> git.lizzy.rs Git - rust.git/commitdiff
seems like for generators we cannot access the freevars
authorRalf Jung <post@ralfj.de>
Tue, 9 Oct 2018 20:44:20 +0000 (22:44 +0200)
committerRalf Jung <post@ralfj.de>
Sat, 13 Oct 2018 07:09:03 +0000 (09:09 +0200)
src/librustc_mir/interpret/validity.rs

index 0c1dc092ce1479a830db749c5de3f38c8398e5bc..e2fa4b15f819d556f6853dd0eb7299cc1df72a30 100644 (file)
@@ -559,12 +559,16 @@ fn aggregate_field_path_elem(&self, layout: TyLayout<'tcx>, field: usize) -> Pat
             // generators and closures.
             ty::Closure(def_id, _) | ty::Generator(def_id, _, _) => {
                 if let Some(node_id) = self.tcx.hir.as_local_node_id(def_id) {
-                    let freevar = self.tcx.with_freevars(node_id, |fv| fv[field]);
-                    PathElem::ClosureVar(self.tcx.hir.name(freevar.var_id()))
-                } else {
-                    // The closure is not local, so we cannot get the name
-                    PathElem::ClosureVar(Symbol::intern(&field.to_string()))
+                    if let Some(freevar) = self.tcx.with_freevars(
+                        node_id,
+                        |fv| fv.get(field).map(|field| *field))
+                    {
+                        return PathElem::ClosureVar(self.tcx.hir.name(freevar.var_id()));
+                    }
                 }
+                // The closure is not local, or the freevars don't match up (seen for a generator!),
+                // so we cannot get the name.
+                PathElem::ClosureVar(Symbol::intern(&field.to_string()))
             }
 
             // tuples