Skip to content

Commit 5c016f4

Browse files
committed
add ability to create region vars with explicit universe
1 parent 3f60043 commit 5c016f4

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

src/librustc/infer/mod.rs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -931,14 +931,22 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
931931
}
932932

933933
/// Create a fresh region variable with the next available index.
934-
///
935-
/// # Parameters
936-
///
937-
/// - `origin`: information about why we created this variable, for use
938-
/// during diagnostics / error-reporting.
934+
/// The variable will be created in the maximum universe created
935+
/// thus far, allowing it to name any region created thus far.
939936
pub fn next_region_var(&self, origin: RegionVariableOrigin) -> ty::Region<'tcx> {
937+
self.next_region_var_in_universe(origin, self.universe())
938+
}
939+
940+
/// Create a fresh region variable with the next available index
941+
/// in the given universe; typically, you can use
942+
/// `next_region_var` and just use the maximal universe.
943+
pub fn next_region_var_in_universe(
944+
&self,
945+
origin: RegionVariableOrigin,
946+
universe: ty::UniverseIndex,
947+
) -> ty::Region<'tcx> {
940948
let region_var = self.borrow_region_constraints()
941-
.new_region_var(self.universe(), origin);
949+
.new_region_var(universe, origin);
942950
self.tcx.mk_region(ty::ReVar(region_var))
943951
}
944952

@@ -952,6 +960,15 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
952960
self.next_region_var(RegionVariableOrigin::NLL(origin))
953961
}
954962

963+
/// Just a convenient wrapper of `next_region_var` for using during NLL.
964+
pub fn next_nll_region_var_in_universe(
965+
&self,
966+
origin: NLLRegionVariableOrigin,
967+
universe: ty::UniverseIndex,
968+
) -> ty::Region<'tcx> {
969+
self.next_region_var_in_universe(RegionVariableOrigin::NLL(origin), universe)
970+
}
971+
955972
pub fn var_for_def(&self, span: Span, param: &ty::GenericParamDef) -> Kind<'tcx> {
956973
match param.kind {
957974
GenericParamDefKind::Lifetime => {

0 commit comments

Comments
 (0)