@@ -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 , BoundTy , BoundVar , Lift , List , Ty , TyCtxt , TypeFlags } ;
26
+ use ty:: { self , BoundVar , Lift , List , Ty , TyCtxt , TypeFlags } ;
27
27
28
28
use rustc_data_structures:: fx:: FxHashMap ;
29
29
use rustc_data_structures:: indexed_vec:: Idx ;
@@ -339,20 +339,51 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for Canonicalizer<'cx, 'gcx, 'tcx>
339
339
340
340
fn fold_ty ( & mut self , t : Ty < ' tcx > ) -> Ty < ' tcx > {
341
341
match t. sty {
342
- ty:: Infer ( ty:: TyVar ( _) ) => self . canonicalize_ty_var ( CanonicalTyVarKind :: General , t) ,
342
+ ty:: Infer ( ty:: TyVar ( vid) ) => {
343
+ match self . infcx . unwrap ( ) . probe_ty_var ( vid) {
344
+ // `t` could be a float / int variable: canonicalize that instead
345
+ Ok ( t) => self . fold_ty ( t) ,
346
+
347
+ // `TyVar(vid)` is unresolved, track its universe index in the canonicalized
348
+ // result
349
+ Err ( ui) => self . canonicalize_ty_var (
350
+ CanonicalVarInfo {
351
+ kind : CanonicalVarKind :: Ty ( CanonicalTyVarKind :: General ( ui) )
352
+ } ,
353
+ t
354
+ )
355
+ }
356
+ }
343
357
344
- ty:: Infer ( ty:: IntVar ( _) ) => self . canonicalize_ty_var ( CanonicalTyVarKind :: Int , t) ,
358
+ ty:: Infer ( ty:: IntVar ( _) ) => self . canonicalize_ty_var (
359
+ CanonicalVarInfo {
360
+ kind : CanonicalVarKind :: Ty ( CanonicalTyVarKind :: Int )
361
+ } ,
362
+ t
363
+ ) ,
345
364
346
- ty:: Infer ( ty:: FloatVar ( _) ) => self . canonicalize_ty_var ( CanonicalTyVarKind :: Float , t) ,
365
+ ty:: Infer ( ty:: FloatVar ( _) ) => self . canonicalize_ty_var (
366
+ CanonicalVarInfo {
367
+ kind : CanonicalVarKind :: Ty ( CanonicalTyVarKind :: Float )
368
+ } ,
369
+ t
370
+ ) ,
347
371
348
372
ty:: Infer ( ty:: FreshTy ( _) )
349
373
| ty:: Infer ( ty:: FreshIntTy ( _) )
350
374
| ty:: Infer ( ty:: FreshFloatTy ( _) ) => {
351
375
bug ! ( "encountered a fresh type during canonicalization" )
352
376
}
353
377
354
- ty:: Bound ( bound_ty) => {
355
- if bound_ty. index >= self . binder_index {
378
+ ty:: Placeholder ( placeholder) => self . canonicalize_ty_var (
379
+ CanonicalVarInfo {
380
+ kind : CanonicalVarKind :: PlaceholderTy ( placeholder)
381
+ } ,
382
+ t
383
+ ) ,
384
+
385
+ ty:: Bound ( debruijn, _) => {
386
+ if debruijn >= self . binder_index {
356
387
bug ! ( "escaping bound type during canonicalization" )
357
388
} else {
358
389
t
@@ -408,9 +439,13 @@ impl<'cx, 'gcx, 'tcx> Canonicalizer<'cx, 'gcx, 'tcx> {
408
439
V : TypeFoldable < ' tcx > + Lift < ' gcx > ,
409
440
{
410
441
let needs_canonical_flags = if canonicalize_region_mode. any ( ) {
411
- TypeFlags :: HAS_FREE_REGIONS | TypeFlags :: KEEP_IN_LOCAL_TCX
442
+ TypeFlags :: KEEP_IN_LOCAL_TCX |
443
+ TypeFlags :: HAS_FREE_REGIONS | // `HAS_RE_PLACEHOLDER` implies `HAS_FREE_REGIONS`
444
+ TypeFlags :: HAS_TY_PLACEHOLDER
412
445
} else {
413
- TypeFlags :: KEEP_IN_LOCAL_TCX
446
+ TypeFlags :: KEEP_IN_LOCAL_TCX |
447
+ TypeFlags :: HAS_RE_PLACEHOLDER |
448
+ TypeFlags :: HAS_TY_PLACEHOLDER
414
449
} ;
415
450
416
451
let gcx = tcx. global_tcx ( ) ;
@@ -574,17 +609,14 @@ impl<'cx, 'gcx, 'tcx> Canonicalizer<'cx, 'gcx, 'tcx> {
574
609
/// if `ty_var` is bound to anything; if so, canonicalize
575
610
/// *that*. Otherwise, create a new canonical variable for
576
611
/// `ty_var`.
577
- fn canonicalize_ty_var ( & mut self , ty_kind : CanonicalTyVarKind , ty_var : Ty < ' tcx > ) -> Ty < ' tcx > {
612
+ fn canonicalize_ty_var ( & mut self , info : CanonicalVarInfo , ty_var : Ty < ' tcx > ) -> Ty < ' tcx > {
578
613
let infcx = self . infcx . expect ( "encountered ty-var without infcx" ) ;
579
614
let bound_to = infcx. shallow_resolve ( ty_var) ;
580
615
if bound_to != ty_var {
581
616
self . fold_ty ( bound_to)
582
617
} else {
583
- let info = CanonicalVarInfo {
584
- kind : CanonicalVarKind :: Ty ( ty_kind) ,
585
- } ;
586
618
let var = self . canonical_var ( info, ty_var. into ( ) ) ;
587
- self . tcx ( ) . mk_ty ( ty:: Bound ( BoundTy :: new ( self . binder_index , var) ) )
619
+ self . tcx ( ) . mk_ty ( ty:: Bound ( self . binder_index , var. into ( ) ) )
588
620
}
589
621
}
590
622
}
0 commit comments