about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2017-11-05 14:42:56 -0500
committerNiko Matsakis <niko@alum.mit.edu>2017-11-16 05:57:44 -0500
commit1430a600ded4b3697fee8ce16fdb6714dbbc06ba (patch)
tree2d647e86e118215f591252f2d7a8fa459f60400b /src
parent1efcf1a115f4f4501e1a9de1e57dd3b00c0bc863 (diff)
downloadrust-1430a600ded4b3697fee8ce16fdb6714dbbc06ba.tar.gz
rust-1430a600ded4b3697fee8ce16fdb6714dbbc06ba.zip
add method `take_and_reset_region_constraints` to `InferCtxt`
Diffstat (limited to 'src')
-rw-r--r--src/librustc/infer/mod.rs16
-rw-r--r--src/librustc/infer/region_constraints/mod.rs11
2 files changed, 26 insertions, 1 deletions
diff --git a/src/librustc/infer/mod.rs b/src/librustc/infer/mod.rs
index a1ad65a6c4a..21f427fa80c 100644
--- a/src/librustc/infer/mod.rs
+++ b/src/librustc/infer/mod.rs
@@ -16,7 +16,7 @@ pub use self::SubregionOrigin::*;
 pub use self::ValuePairs::*;
 pub use ty::IntVarValue;
 pub use self::freshen::TypeFreshener;
-pub use self::region_constraints::{GenericKind, VerifyBound};
+pub use self::region_constraints::{GenericKind, VerifyBound, RegionConstraintData};
 
 use hir::def_id::DefId;
 use middle::free_region::{FreeRegionMap, RegionRelations};
@@ -1152,6 +1152,20 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
         }
     }
 
+    /// Obtains (and clears) the current set of region
+    /// constraints. The inference context is still usable: further
+    /// unifications will simply add new constraints.
+    ///
+    /// This method is not meant to be used with normal lexical region
+    /// resolution. Rather, it is used in the NLL mode as a kind of
+    /// interim hack: basically we run normal type-check and generate
+    /// region constraints as normal, but then we take them and
+    /// translate them into the form that the NLL solver
+    /// understands. See the NLL module for mode details.
+    pub fn take_and_reset_region_constraints(&self) -> RegionConstraintData<'tcx> {
+        self.borrow_region_constraints().take_and_reset_data()
+    }
+
     pub fn ty_to_string(&self, t: Ty<'tcx>) -> String {
         self.resolve_type_vars_if_possible(&t).to_string()
     }
diff --git a/src/librustc/infer/region_constraints/mod.rs b/src/librustc/infer/region_constraints/mod.rs
index 36e5e303957..057f1b35ac1 100644
--- a/src/librustc/infer/region_constraints/mod.rs
+++ b/src/librustc/infer/region_constraints/mod.rs
@@ -285,10 +285,21 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
     }
 
     /// Once all the constraints have been gathered, extract out the final data.
+    ///
+    /// Not legal during a snapshot.
     pub fn into_origins_and_data(self) -> (VarOrigins, RegionConstraintData<'tcx>) {
+        assert!(!self.in_snapshot());
         (self.var_origins, self.data)
     }
 
+    /// Takes (and clears) the current set of constraints. Note that the set of
+    /// variables remains intact.
+    ///
+    /// Not legal during a snapshot.
+    pub fn take_and_reset_data(&mut self) -> RegionConstraintData<'tcx> {
+        mem::replace(&mut self.data, RegionConstraintData::default())
+    }
+
     fn in_snapshot(&self) -> bool {
         !self.undo_log.is_empty()
     }