Skip to content

Commit 2f69b79

Browse files
committed
give a universe to region variables
1 parent 6234a89 commit 2f69b79

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

src/librustc/infer/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
884884
/// during diagnostics / error-reporting.
885885
pub fn next_region_var(&self, origin: RegionVariableOrigin)
886886
-> ty::Region<'tcx> {
887-
self.tcx.mk_region(ty::ReVar(self.borrow_region_constraints().new_region_var(origin)))
887+
let region_var = self.borrow_region_constraints()
888+
.new_region_var(self.universe, origin);
889+
self.tcx.mk_region(ty::ReVar(region_var))
888890
}
889891

890892
/// Number of region variables created so far.

src/librustc/infer/region_constraints/mod.rs

+31-5
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ use ty::ReStatic;
2525
use ty::{BrFresh, ReLateBound, ReSkolemized, ReVar};
2626

2727
use std::collections::BTreeMap;
28-
use std::fmt;
29-
use std::mem;
30-
use std::u32;
28+
use std::{cmp, fmt, mem, u32};
3129

3230
mod taint;
3331

@@ -233,6 +231,7 @@ type CombineMap<'tcx> = FxHashMap<TwoRegions<'tcx>, RegionVid>;
233231
#[derive(Debug, Clone, Copy)]
234232
pub struct RegionVariableInfo {
235233
pub origin: RegionVariableOrigin,
234+
pub universe: ty::UniverseIndex,
236235
}
237236

238237
pub struct RegionSnapshot {
@@ -438,9 +437,12 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
438437
}
439438
}
440439

441-
pub fn new_region_var(&mut self, origin: RegionVariableOrigin) -> RegionVid {
440+
pub fn new_region_var(&mut self,
441+
universe: ty::UniverseIndex,
442+
origin: RegionVariableOrigin) -> RegionVid {
442443
let vid = self.var_infos.push(RegionVariableInfo {
443444
origin,
445+
universe,
444446
});
445447

446448
let u_vid = self.unification_table
@@ -457,6 +459,11 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
457459
return vid;
458460
}
459461

462+
/// Returns the universe for the given variable.
463+
pub fn var_universe(&self, vid: RegionVid) -> ty::UniverseIndex {
464+
self.var_infos[vid].universe
465+
}
466+
460467
/// Returns the origin for the given variable.
461468
pub fn var_origin(&self, vid: RegionVid) -> RegionVariableOrigin {
462469
self.var_infos[vid].origin
@@ -812,7 +819,10 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
812819
if let Some(&c) = self.combine_map(t).get(&vars) {
813820
return tcx.mk_region(ReVar(c));
814821
}
815-
let c = self.new_region_var(MiscVariable(origin.span()));
822+
let a_universe = self.universe(a);
823+
let b_universe = self.universe(b);
824+
let c_universe = cmp::max(a_universe, b_universe);
825+
let c = self.new_region_var(c_universe, MiscVariable(origin.span()));
816826
self.combine_map(t).insert(vars, c);
817827
if self.in_snapshot() {
818828
self.undo_log.push(AddCombination(t, vars));
@@ -828,6 +838,22 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
828838
new_r
829839
}
830840

841+
fn universe(&self, region: Region<'tcx>) -> ty::UniverseIndex {
842+
match *region {
843+
ty::ReScope(..) |
844+
ty::ReStatic |
845+
ty::ReEmpty |
846+
ty::ReErased |
847+
ty::ReFree(..) |
848+
ty::ReEarlyBound(..) => ty::UniverseIndex::ROOT,
849+
ty::ReSkolemized(universe, _) => universe,
850+
ty::ReClosureBound(vid) |
851+
ty::ReVar(vid) => self.var_universe(vid),
852+
ty::ReLateBound(..) =>
853+
bug!("universe(): encountered bound region {:?}", region),
854+
}
855+
}
856+
831857
pub fn vars_created_since_snapshot(&self, mark: &RegionSnapshot) -> Vec<RegionVid> {
832858
self.undo_log[mark.length..]
833859
.iter()

0 commit comments

Comments
 (0)