@@ -23,7 +23,7 @@ use infer::InferCtxt;
23
23
use std:: sync:: atomic:: Ordering ;
24
24
use ty:: fold:: { TypeFoldable , TypeFolder } ;
25
25
use ty:: subst:: Kind ;
26
- use ty:: { self , BoundTyIndex , Lift , List , Ty , TyCtxt , TypeFlags } ;
26
+ use ty:: { self , BoundTy , BoundTyIndex , Lift , List , Ty , TyCtxt , TypeFlags } ;
27
27
28
28
use rustc_data_structures:: fx:: FxHashMap ;
29
29
use rustc_data_structures:: indexed_vec:: Idx ;
@@ -283,7 +283,7 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for Canonicalizer<'cx, 'gcx, 'tcx>
283
283
bug ! ( "encountered a fresh type during canonicalization" )
284
284
}
285
285
286
- ty:: Infer ( ty:: CanonicalTy ( _) ) => {
286
+ ty:: Infer ( ty:: BoundTy ( _) ) => {
287
287
bug ! ( "encountered a canonical type during canonicalization" )
288
288
}
289
289
@@ -393,7 +393,7 @@ impl<'cx, 'gcx, 'tcx> Canonicalizer<'cx, 'gcx, 'tcx> {
393
393
/// or returns an existing variable if `kind` has already been
394
394
/// seen. `kind` is expected to be an unbound variable (or
395
395
/// 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 {
397
397
let Canonicalizer {
398
398
variables,
399
399
query_state,
@@ -408,7 +408,7 @@ impl<'cx, 'gcx, 'tcx> Canonicalizer<'cx, 'gcx, 'tcx> {
408
408
// avoid allocations in those cases. We also don't use `indices` to
409
409
// determine if a kind has been seen before until the limit of 8 has
410
410
// been exceeded, to also avoid allocations for `indices`.
411
- if !var_values. spilled ( ) {
411
+ let var = if !var_values. spilled ( ) {
412
412
// `var_values` is stack-allocated. `indices` isn't used yet. Do a
413
413
// direct linear search of `var_values`.
414
414
if let Some ( idx) = var_values. iter ( ) . position ( |& k| k == kind) {
@@ -442,15 +442,21 @@ impl<'cx, 'gcx, 'tcx> Canonicalizer<'cx, 'gcx, 'tcx> {
442
442
assert_eq ! ( variables. len( ) , var_values. len( ) ) ;
443
443
BoundTyIndex :: new ( variables. len ( ) - 1 )
444
444
} )
445
+ } ;
446
+
447
+ BoundTy {
448
+ level : ty:: INNERMOST ,
449
+ var,
445
450
}
446
451
}
447
452
448
453
fn canonical_var_for_region ( & mut self , r : ty:: Region < ' tcx > ) -> ty:: Region < ' tcx > {
449
454
let info = CanonicalVarInfo {
450
455
kind : CanonicalVarKind :: Region ,
451
456
} ;
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 ) )
454
460
}
455
461
456
462
/// Given a type variable `ty_var` of the given kind, first check
@@ -466,8 +472,9 @@ impl<'cx, 'gcx, 'tcx> Canonicalizer<'cx, 'gcx, 'tcx> {
466
472
let info = CanonicalVarInfo {
467
473
kind : CanonicalVarKind :: Ty ( ty_kind) ,
468
474
} ;
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) )
471
478
}
472
479
}
473
480
}
0 commit comments