]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #47353 - nikomatsakis:nll-issue-47189, r=pnkfelix+nmatsakis
authorbors <bors@rust-lang.org>
Mon, 22 Jan 2018 11:11:47 +0000 (11:11 +0000)
committerbors <bors@rust-lang.org>
Mon, 22 Jan 2018 11:11:47 +0000 (11:11 +0000)
renumber regions in generators

This fixes #47189, but I think we still have to double check various things around how to treat generators in MIR type check + borrow check (e.g., what borrows should be invalidated by a `Suspend`? What consistency properties should type check be enforcing anyway around the "interior" type?)

Also fixes #47587 thanks to @spastorino's commit.

r? @pnkfelix

1  2 
src/librustc_mir/borrow_check/nll/universal_regions.rs
src/librustc_mir/util/pretty.rs

index 7703235b4b7411acae1f3b74a69f8c19f18aa282,e426457a3493d8564dd85c7bb3ad979a24d23fab..e47e3c728dff21327697f69dbd55674052c23fa4
@@@ -96,6 -96,8 +96,8 @@@ pub struct UniversalRegions<'tcx> 
      /// our special inference variable there, we would mess that up.
      pub region_bound_pairs: Vec<(ty::Region<'tcx>, GenericKind<'tcx>)>,
  
+     pub yield_ty: Option<Ty<'tcx>>,
      relations: UniversalRegionRelations,
  }
  
@@@ -505,6 -507,13 +507,13 @@@ impl<'cx, 'gcx, 'tcx> UniversalRegionsB
              num_universals
          );
  
+         let yield_ty = match defining_ty {
+             DefiningTy::Generator(def_id, substs, _) => {
+                 Some(substs.generator_yield_ty(def_id, self.infcx.tcx))
+             }
+             _ => None,
+         };
          UniversalRegions {
              indices,
              fr_static,
              unnormalized_output_ty,
              unnormalized_input_tys,
              region_bound_pairs: self.region_bound_pairs,
+             yield_ty: yield_ty,
              relations: self.relations,
          }
      }
  
              DefiningTy::FnDef(_, substs) => substs,
  
 -            // When we encounter other sorts of constant
 -            // expressions, such as the `22` in `[foo; 22]`, we can
 -            // get the type `usize` here. For now, just return an
 -            // empty vector of substs in this case, since there are no
 -            // generics in scope in such expressions right now.
 +            // When we encounter a constant body, just return whatever
 +            // substitutions are in scope for that constant.
              DefiningTy::Const(_) => {
 -                assert!(identity_substs.is_empty());
                  identity_substs
              }
          };
                  sig.inputs_and_output()
              }
  
 -            // This happens on things like `[foo; 22]`. Hence, no
 -            // inputs, one output, but it seems like we need a more
 -            // general way to handle this category of MIR.
 +            // For a constant body, there are no inputs, and one
 +            // "output" (the type of the constant).
              DefiningTy::Const(ty) => ty::Binder::dummy(tcx.mk_type_list(iter::once(ty))),
          }
      }
@@@ -794,10 -809,12 +804,12 @@@ impl<'tcx> UniversalRegionIndices<'tcx
      /// during initialization. Relies on the `indices` map having been
      /// fully initialized.
      pub fn to_region_vid(&self, r: ty::Region<'tcx>) -> RegionVid {
-         match r {
-             ty::ReEarlyBound(..) | ty::ReStatic => *self.indices.get(&r).unwrap(),
-             ty::ReVar(..) => r.to_region_vid(),
-             _ => bug!("cannot convert `{:?}` to a region vid", r),
+         if let ty::ReVar(..) = r {
+             r.to_region_vid()
+         } else {
+             *self.indices.get(&r).unwrap_or_else(|| {
+                 bug!("cannot convert `{:?}` to a region vid", r)
+             })
          }
      }
  
index 78d55ad34ed45a77fe97d293120c910d543beef6,6ed797f70513d98ea8b53ce268d0b6f5188b8da6..6ab5fee79c661e72b82d7f7c85cb5dcc1f541c73
@@@ -189,7 -189,11 +189,7 @@@ fn dump_path
      };
  
      let mut file_path = PathBuf::new();
 -
 -    if let Some(ref file_dir) = tcx.sess.opts.debugging_opts.dump_mir_dir {
 -        let p = Path::new(file_dir);
 -        file_path.push(p);
 -    };
 +    file_path.push(Path::new(&tcx.sess.opts.debugging_opts.dump_mir_dir));
  
      let item_name = tcx.hir
          .def_path(source.def_id)
@@@ -518,7 -522,7 +518,7 @@@ pub fn write_mir_intro<'a, 'gcx, 'tcx>
      w: &mut Write,
  ) -> io::Result<()> {
      write_mir_sig(tcx, src, mir, w)?;
-     writeln!(w, " {{")?;
+     writeln!(w, "{{")?;
  
      // construct a scope tree and write it out
      let mut scope_tree: FxHashMap<VisibilityScope, Vec<VisibilityScope>> = FxHashMap();
@@@ -581,13 -585,20 +581,20 @@@ fn write_mir_sig(tcx: TyCtxt, src: MirS
                  write!(w, "{:?}: {}", Place::Local(arg), mir.local_decls[arg].ty)?;
              }
  
-             write!(w, ") -> {}", mir.return_ty())
+             write!(w, ") -> {}", mir.return_ty())?;
          }
          (hir::BodyOwnerKind::Const, _) | (hir::BodyOwnerKind::Static(_), _) | (_, Some(_)) => {
              assert_eq!(mir.arg_count, 0);
-             write!(w, ": {} =", mir.return_ty())
+             write!(w, ": {} =", mir.return_ty())?;
          }
      }
+     if let Some(yield_ty) = mir.yield_ty {
+         writeln!(w)?;
+         writeln!(w, "yields {}", yield_ty)?;
+     }
+     Ok(())
  }
  
  fn write_temp_decls(mir: &Mir, w: &mut Write) -> io::Result<()> {