@@ -23,7 +23,7 @@ use infer::InferCtxt;
2323use std:: sync:: atomic:: Ordering ;
2424use ty:: fold:: { TypeFoldable , TypeFolder } ;
2525use ty:: subst:: Kind ;
26- use ty:: { self , BoundTyIndex , Lift , List , Ty , TyCtxt , TypeFlags } ;
26+ use ty:: { self , BoundTy , BoundTyIndex , Lift , List , Ty , TyCtxt , TypeFlags } ;
2727
2828use rustc_data_structures:: fx:: FxHashMap ;
2929use rustc_data_structures:: indexed_vec:: Idx ;
@@ -283,7 +283,7 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for Canonicalizer<'cx, 'gcx, 'tcx>
283283 bug ! ( "encountered a fresh type during canonicalization" )
284284 }
285285
286- ty:: Infer ( ty:: CanonicalTy ( _) ) => {
286+ ty:: Infer ( ty:: BoundTy ( _) ) => {
287287 bug ! ( "encountered a canonical type during canonicalization" )
288288 }
289289
@@ -393,7 +393,7 @@ impl<'cx, 'gcx, 'tcx> Canonicalizer<'cx, 'gcx, 'tcx> {
393393 /// or returns an existing variable if `kind` has already been
394394 /// seen. `kind` is expected to be an unbound variable (or
395395 /// potentially a free region).
396- fn canonical_var ( & mut self , info : CanonicalVarInfo , kind : Kind < ' tcx > ) -> BoundTyIndex {
396+ fn canonical_var ( & mut self , info : CanonicalVarInfo , kind : Kind < ' tcx > ) -> BoundTy {
397397 let Canonicalizer {
398398 variables,
399399 query_state,
@@ -408,7 +408,7 @@ impl<'cx, 'gcx, 'tcx> Canonicalizer<'cx, 'gcx, 'tcx> {
408408 // avoid allocations in those cases. We also don't use `indices` to
409409 // determine if a kind has been seen before until the limit of 8 has
410410 // been exceeded, to also avoid allocations for `indices`.
411- if !var_values. spilled ( ) {
411+ let var = if !var_values. spilled ( ) {
412412 // `var_values` is stack-allocated. `indices` isn't used yet. Do a
413413 // direct linear search of `var_values`.
414414 if let Some ( idx) = var_values. iter ( ) . position ( |& k| k == kind) {
@@ -442,15 +442,21 @@ impl<'cx, 'gcx, 'tcx> Canonicalizer<'cx, 'gcx, 'tcx> {
442442 assert_eq ! ( variables. len( ) , var_values. len( ) ) ;
443443 BoundTyIndex :: new ( variables. len ( ) - 1 )
444444 } )
445+ } ;
446+
447+ BoundTy {
448+ level : ty:: INNERMOST ,
449+ var,
445450 }
446451 }
447452
448453 fn canonical_var_for_region ( & mut self , r : ty:: Region < ' tcx > ) -> ty:: Region < ' tcx > {
449454 let info = CanonicalVarInfo {
450455 kind : CanonicalVarKind :: Region ,
451456 } ;
452- let cvar = self . canonical_var ( info, r. into ( ) ) ;
453- self . tcx ( ) . mk_region ( ty:: ReCanonical ( cvar) )
457+ let b = self . canonical_var ( info, r. into ( ) ) ;
458+ debug_assert_eq ! ( ty:: INNERMOST , b. level) ;
459+ self . tcx ( ) . mk_region ( ty:: ReCanonical ( b. var ) )
454460 }
455461
456462 /// Given a type variable `ty_var` of the given kind, first check
@@ -466,8 +472,9 @@ impl<'cx, 'gcx, 'tcx> Canonicalizer<'cx, 'gcx, 'tcx> {
466472 let info = CanonicalVarInfo {
467473 kind : CanonicalVarKind :: Ty ( ty_kind) ,
468474 } ;
469- let cvar = self . canonical_var ( info, ty_var. into ( ) ) ;
470- self . tcx ( ) . mk_infer ( ty:: InferTy :: CanonicalTy ( cvar) )
475+ let b = self . canonical_var ( info, ty_var. into ( ) ) ;
476+ debug_assert_eq ! ( ty:: INNERMOST , b. level) ;
477+ self . tcx ( ) . mk_infer ( ty:: InferTy :: BoundTy ( b) )
471478 }
472479 }
473480}
0 commit comments