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() }