@@ -122,6 +122,7 @@ impl CanonicalVarInfo {
122122 pub fn is_existential ( & self ) -> bool {
123123 match self . kind {
124124 CanonicalVarKind :: Ty ( _) => true ,
125+ CanonicalVarKind :: PlaceholderTy ( _) => false ,
125126 CanonicalVarKind :: Region ( _) => true ,
126127 CanonicalVarKind :: PlaceholderRegion ( ..) => false ,
127128 }
@@ -136,6 +137,9 @@ pub enum CanonicalVarKind {
136137 /// Some kind of type inference variable.
137138 Ty ( CanonicalTyVarKind ) ,
138139
140+ /// A "placeholder" that represents "any type".
141+ PlaceholderTy ( ty:: PlaceholderType ) ,
142+
139143 /// Region variable `'?R`.
140144 Region ( ty:: UniverseIndex ) ,
141145
@@ -148,12 +152,12 @@ pub enum CanonicalVarKind {
148152impl CanonicalVarKind {
149153 pub fn universe ( self ) -> ty:: UniverseIndex {
150154 match self {
151- // At present, we don't support higher-ranked
152- // quantification over types, so all type variables are in
153- // the root universe.
154- CanonicalVarKind :: Ty ( _ ) => ty :: UniverseIndex :: ROOT ,
155+ CanonicalVarKind :: Ty ( kind ) => match kind {
156+ CanonicalTyVarKind :: General ( ui ) => ui ,
157+ CanonicalTyVarKind :: Float | CanonicalTyVarKind :: Int => ty :: UniverseIndex :: ROOT ,
158+ }
155159
156- // Region variables can be created in sub-universes.
160+ CanonicalVarKind :: PlaceholderTy ( placeholder ) => placeholder . universe ,
157161 CanonicalVarKind :: Region ( ui) => ui,
158162 CanonicalVarKind :: PlaceholderRegion ( placeholder) => placeholder. universe ,
159163 }
@@ -168,7 +172,7 @@ impl CanonicalVarKind {
168172#[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash , RustcDecodable , RustcEncodable ) ]
169173pub enum CanonicalTyVarKind {
170174 /// General type variable `?T` that can be unified with arbitrary types.
171- General ,
175+ General ( ty :: UniverseIndex ) ,
172176
173177 /// Integral type variable `?I` (that can only be unified with integral types).
174178 Int ,
@@ -358,8 +362,11 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
358362 match cv_info. kind {
359363 CanonicalVarKind :: Ty ( ty_kind) => {
360364 let ty = match ty_kind {
361- CanonicalTyVarKind :: General => {
362- self . next_ty_var ( TypeVariableOrigin :: MiscVariable ( span) )
365+ CanonicalTyVarKind :: General ( ui) => {
366+ self . next_ty_var_in_universe (
367+ TypeVariableOrigin :: MiscVariable ( span) ,
368+ universe_map ( ui)
369+ )
363370 }
364371
365372 CanonicalTyVarKind :: Int => self . tcx . mk_int_var ( self . next_int_var_id ( ) ) ,
@@ -369,6 +376,15 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
369376 ty. into ( )
370377 }
371378
379+ CanonicalVarKind :: PlaceholderTy ( ty:: PlaceholderType { universe, name } ) => {
380+ let universe_mapped = universe_map ( universe) ;
381+ let placeholder_mapped = ty:: PlaceholderType {
382+ universe : universe_mapped,
383+ name,
384+ } ;
385+ self . tcx . mk_ty ( ty:: Placeholder ( placeholder_mapped) ) . into ( )
386+ }
387+
372388 CanonicalVarKind :: Region ( ui) => self . next_region_var_in_universe (
373389 RegionVariableOrigin :: MiscVariable ( span) ,
374390 universe_map ( ui) ,
@@ -380,9 +396,7 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
380396 universe : universe_mapped,
381397 name,
382398 } ;
383- self . tcx
384- . mk_region ( ty:: RePlaceholder ( placeholder_mapped) )
385- . into ( )
399+ self . tcx . mk_region ( ty:: RePlaceholder ( placeholder_mapped) ) . into ( )
386400 }
387401 }
388402 }
0 commit comments