]> git.lizzy.rs Git - rust.git/commitdiff
Make error reporting work on generator upvars. Fixes #47793, #47805
authorJohn Kåre Alsaker <john.kare.alsaker@gmail.com>
Sun, 28 Jan 2018 18:50:48 +0000 (19:50 +0100)
committerJohn Kåre Alsaker <john.kare.alsaker@gmail.com>
Mon, 29 Jan 2018 09:02:03 +0000 (10:02 +0100)
src/librustc_mir/borrow_check/error_reporting.rs

index 7bd3b6e39f053b46ca7ab2ce3558049c6ede6ee6..7fadc4b36e44fe4ab6c5b3abef36d7bd7fa13db1 100644 (file)
@@ -746,12 +746,12 @@ fn describe_field_from_ty(&self, ty: &ty::Ty, field: Field) -> String {
                     self.describe_field_from_ty(&tnm.ty, field)
                 }
                 ty::TyArray(ty, _) | ty::TySlice(ty) => self.describe_field_from_ty(&ty, field),
-                ty::TyClosure(closure_def_id, _) => {
+                ty::TyClosure(def_id, _) | ty::TyGenerator(def_id, _, _) => {
                     // Convert the def-id into a node-id. node-ids are only valid for
                     // the local code in the current crate, so this returns an `Option` in case
                     // the closure comes from another crate. But in that case we wouldn't
                     // be borrowck'ing it, so we can just unwrap:
-                    let node_id = self.tcx.hir.as_local_node_id(closure_def_id).unwrap();
+                    let node_id = self.tcx.hir.as_local_node_id(def_id).unwrap();
                     let freevar = self.tcx.with_freevars(node_id, |fv| fv[field.index()]);
 
                     self.tcx.hir.name(freevar.var_id()).to_string()