]> git.lizzy.rs Git - rust.git/commitdiff
add ability to create region vars with explicit universe
authorNiko Matsakis <niko@alum.mit.edu>
Wed, 29 Aug 2018 18:33:38 +0000 (14:33 -0400)
committerNiko Matsakis <niko@alum.mit.edu>
Sun, 9 Sep 2018 18:14:41 +0000 (14:14 -0400)
src/librustc/infer/mod.rs

index 66aa7d6d8eaf58262c16ccad45b48c55625ba8af..e628a3458f9e628c0ed450caae519aea28dd4d12 100644 (file)
@@ -931,14 +931,22 @@ pub fn next_float_var_id(&self) -> FloatVid {
     }
 
     /// Create a fresh region variable with the next available index.
-    ///
-    /// # Parameters
-    ///
-    /// - `origin`: information about why we created this variable, for use
-    ///   during diagnostics / error-reporting.
+    /// The variable will be created in the maximum universe created
+    /// thus far, allowing it to name any region created thus far.
     pub fn next_region_var(&self, origin: RegionVariableOrigin) -> ty::Region<'tcx> {
+        self.next_region_var_in_universe(origin, self.universe())
+    }
+
+    /// Create a fresh region variable with the next available index
+    /// in the given universe; typically, you can use
+    /// `next_region_var` and just use the maximal universe.
+    pub fn next_region_var_in_universe(
+        &self,
+        origin: RegionVariableOrigin,
+        universe: ty::UniverseIndex,
+    ) -> ty::Region<'tcx> {
         let region_var = self.borrow_region_constraints()
-            .new_region_var(self.universe(), origin);
+            .new_region_var(universe, origin);
         self.tcx.mk_region(ty::ReVar(region_var))
     }
 
@@ -952,6 +960,15 @@ pub fn next_nll_region_var(&self, origin: NLLRegionVariableOrigin) -> ty::Region
         self.next_region_var(RegionVariableOrigin::NLL(origin))
     }
 
+    /// Just a convenient wrapper of `next_region_var` for using during NLL.
+    pub fn next_nll_region_var_in_universe(
+        &self,
+        origin: NLLRegionVariableOrigin,
+        universe: ty::UniverseIndex,
+    ) -> ty::Region<'tcx> {
+        self.next_region_var_in_universe(RegionVariableOrigin::NLL(origin), universe)
+    }
+
     pub fn var_for_def(&self, span: Span, param: &ty::GenericParamDef) -> Kind<'tcx> {
         match param.kind {
             GenericParamDefKind::Lifetime => {