Skip to content

Commit 9d0eaf5

Browse files
committed
add method take_and_reset_region_constraints to InferCtxt
1 parent e9f5933 commit 9d0eaf5

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/librustc/infer/mod.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub use self::SubregionOrigin::*;
1616
pub use self::ValuePairs::*;
1717
pub use ty::IntVarValue;
1818
pub use self::freshen::TypeFreshener;
19-
pub use self::region_constraints::{GenericKind, VerifyBound};
19+
pub use self::region_constraints::{GenericKind, VerifyBound, RegionConstraintData};
2020

2121
use hir::def_id::DefId;
2222
use middle::free_region::{FreeRegionMap, RegionRelations};
@@ -1152,6 +1152,20 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
11521152
}
11531153
}
11541154

1155+
/// Obtains (and clears) the current set of region
1156+
/// constraints. The inference context is still usable: further
1157+
/// unifications will simply add new constraints.
1158+
///
1159+
/// This method is not meant to be used with normal lexical region
1160+
/// resolution. Rather, it is used in the NLL mode as a kind of
1161+
/// interim hack: basically we run normal type-check and generate
1162+
/// region constraints as normal, but then we take them and
1163+
/// translate them into the form that the NLL solver
1164+
/// understands. See the NLL module for mode details.
1165+
pub fn take_and_reset_region_constraints(&self) -> RegionConstraintData<'tcx> {
1166+
self.borrow_region_constraints().take_and_reset_data()
1167+
}
1168+
11551169
pub fn ty_to_string(&self, t: Ty<'tcx>) -> String {
11561170
self.resolve_type_vars_if_possible(&t).to_string()
11571171
}

src/librustc/infer/region_constraints/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,21 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
285285
}
286286

287287
/// Once all the constraints have been gathered, extract out the final data.
288+
///
289+
/// Not legal during a snapshot.
288290
pub fn into_origins_and_data(self) -> (VarOrigins, RegionConstraintData<'tcx>) {
291+
assert!(!self.in_snapshot());
289292
(self.var_origins, self.data)
290293
}
291294

295+
/// Takes (and clears) the current set of constraints. Note that the set of
296+
/// variables remains intact.
297+
///
298+
/// Not legal during a snapshot.
299+
pub fn take_and_reset_data(&mut self) -> RegionConstraintData<'tcx> {
300+
mem::replace(&mut self.data, RegionConstraintData::default())
301+
}
302+
292303
fn in_snapshot(&self) -> bool {
293304
!self.undo_log.is_empty()
294305
}

0 commit comments

Comments
 (0)