@@ -53,6 +53,7 @@ mod substitute;
5353/// numbered starting from 0 in order of first appearance.
5454#[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash , RustcDecodable , RustcEncodable ) ]
5555pub struct Canonical < ' gcx , V > {
56+ pub max_universe : ty:: UniverseIndex ,
5657 pub variables : CanonicalVarInfos < ' gcx > ,
5758 pub value : V ,
5859}
@@ -95,6 +96,12 @@ pub struct CanonicalVarInfo {
9596 pub kind : CanonicalVarKind ,
9697}
9798
99+ impl CanonicalVarInfo {
100+ pub fn universe ( self ) -> ty:: UniverseIndex {
101+ self . kind . universe ( )
102+ }
103+ }
104+
98105/// Describes the "kind" of the canonical variable. This is a "kind"
99106/// in the type-theory sense of the term -- i.e., a "meta" type system
100107/// that analyzes type-like values.
@@ -104,7 +111,22 @@ pub enum CanonicalVarKind {
104111 Ty ( CanonicalTyVarKind ) ,
105112
106113 /// Region variable `'?R`.
107- Region ,
114+ Region ( ty:: UniverseIndex ) ,
115+ }
116+
117+
118+ impl CanonicalVarKind {
119+ pub fn universe ( self ) -> ty:: UniverseIndex {
120+ match self {
121+ // At present, we don't support higher-ranked
122+ // quantification over types, so all type variables are in
123+ // the root universe.
124+ CanonicalVarKind :: Ty ( _) => ty:: UniverseIndex :: ROOT ,
125+
126+ // Region variables can be created in sub-universes.
127+ CanonicalVarKind :: Region ( ui) => ui,
128+ }
129+ }
108130}
109131
110132/// Rust actually has more than one category of type variables;
@@ -220,8 +242,8 @@ impl<'gcx, V> Canonical<'gcx, V> {
220242 /// let b: Canonical<'tcx, (T, Ty<'tcx>)> = a.unchecked_map(|v| (v, ty));
221243 /// ```
222244 pub fn unchecked_map < W > ( self , map_op : impl FnOnce ( V ) -> W ) -> Canonical < ' gcx , W > {
223- let Canonical { variables, value } = self ;
224- Canonical { variables, value : map_op ( value) }
245+ let Canonical { max_universe , variables, value } = self ;
246+ Canonical { max_universe , variables, value : map_op ( value) }
225247 }
226248}
227249
@@ -293,8 +315,8 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
293315 ty. into ( )
294316 }
295317
296- CanonicalVarKind :: Region => self
297- . next_region_var ( RegionVariableOrigin :: MiscVariable ( span) )
318+ CanonicalVarKind :: Region ( ui ) => self
319+ . next_region_var_in_universe ( RegionVariableOrigin :: MiscVariable ( span) , ui )
298320 . into ( ) ,
299321 }
300322 }
@@ -314,6 +336,7 @@ CloneTypeFoldableImpls! {
314336
315337BraceStructTypeFoldableImpl ! {
316338 impl <' tcx, C > TypeFoldable <' tcx> for Canonical <' tcx, C > {
339+ max_universe,
317340 variables,
318341 value,
319342 } where C : TypeFoldable <' tcx>
@@ -322,7 +345,7 @@ BraceStructTypeFoldableImpl! {
322345BraceStructLiftImpl ! {
323346 impl <' a, ' tcx, T > Lift <' tcx> for Canonical <' a, T > {
324347 type Lifted = Canonical <' tcx, T :: Lifted >;
325- variables, value
348+ max_universe , variables, value
326349 } where T : Lift <' tcx>
327350}
328351
0 commit comments