From df8f5375a6b246a4ffee3b074ec749ad95a1f430 Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Wed, 7 Feb 2018 10:16:44 -0700 Subject: [PATCH] introduce `UniverseIndex` into `InferCtxt` Always using root environment for now. --- src/librustc/infer/mod.rs | 12 ++++++++++++ src/librustc/ty/mod.rs | 4 +--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/librustc/infer/mod.rs b/src/librustc/infer/mod.rs index 553926dba8f..08ae535b8e8 100644 --- a/src/librustc/infer/mod.rs +++ b/src/librustc/infer/mod.rs @@ -183,6 +183,17 @@ pub struct InferCtxt<'a, 'gcx: 'a+'tcx, 'tcx: 'a> { // obligations within. This is expected to be done 'late enough' // that all type inference variables have been bound and so forth. pub region_obligations: RefCell)>>, + + /// What is the innermost universe we have created? Starts out as + /// `UniverseIndex::root()` but grows from there as we enter + /// universal quantifiers. + /// + /// NB: At present, we exclude the universal quantifiers on the + /// item we are type-checking, and just consider those names as + /// part of the root universe. So this would only get incremented + /// when we enter into a higher-ranked (`for<..>`) type or trait + /// bound. + pub universe: ty::UniverseIndex, } /// A map returned by `skolemize_late_bound_regions()` indicating the skolemized @@ -455,6 +466,7 @@ pub fn enter(&'tcx mut self, f: F) -> R err_count_on_creation: tcx.sess.err_count(), in_snapshot: Cell::new(false), region_obligations: RefCell::new(vec![]), + universe: ty::UniverseIndex::ROOT, })) } } diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 4fdc247686f..744b92dbe0d 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -1376,9 +1376,7 @@ pub fn is_empty(&self) -> bool { impl UniverseIndex { /// The root universe, where things that the user defined are /// visible. - pub fn root() -> UniverseIndex { - UniverseIndex(0) - } + pub const ROOT: Self = UniverseIndex(0); /// A "subuniverse" corresponds to being inside a `forall` quantifier. /// So, for example, suppose we have this type in universe `U`: