@@ -376,9 +376,18 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'cx, 'tcx> {
376
376
}
377
377
}
378
378
379
- fn fold_ty ( & mut self , t : Ty < ' tcx > ) -> Ty < ' tcx > {
379
+ fn fold_ty ( & mut self , mut t : Ty < ' tcx > ) -> Ty < ' tcx > {
380
380
match * t. kind ( ) {
381
- ty:: Infer ( ty:: TyVar ( vid) ) => {
381
+ ty:: Infer ( ty:: TyVar ( mut vid) ) => {
382
+ // We need to canonicalize the *root* of our ty var.
383
+ // This is so that our canonical response correctly reflects
384
+ // any equated inference vars correctly!
385
+ let root_vid = self . infcx . root_var ( vid) ;
386
+ if root_vid != vid {
387
+ t = self . infcx . tcx . mk_ty_var ( root_vid) ;
388
+ vid = root_vid;
389
+ }
390
+
382
391
debug ! ( "canonical: type var found with vid {:?}" , vid) ;
383
392
match self . infcx . probe_ty_var ( vid) {
384
393
// `t` could be a float / int variable; canonicalize that instead.
@@ -469,9 +478,18 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'cx, 'tcx> {
469
478
}
470
479
}
471
480
472
- fn fold_const ( & mut self , ct : ty:: Const < ' tcx > ) -> ty:: Const < ' tcx > {
481
+ fn fold_const ( & mut self , mut ct : ty:: Const < ' tcx > ) -> ty:: Const < ' tcx > {
473
482
match ct. kind ( ) {
474
- ty:: ConstKind :: Infer ( InferConst :: Var ( vid) ) => {
483
+ ty:: ConstKind :: Infer ( InferConst :: Var ( mut vid) ) => {
484
+ // We need to canonicalize the *root* of our const var.
485
+ // This is so that our canonical response correctly reflects
486
+ // any equated inference vars correctly!
487
+ let root_vid = self . infcx . root_const_var ( vid) ;
488
+ if root_vid != vid {
489
+ ct = self . infcx . tcx . mk_const ( ty:: InferConst :: Var ( root_vid) , ct. ty ( ) ) ;
490
+ vid = root_vid;
491
+ }
492
+
475
493
debug ! ( "canonical: const var found with vid {:?}" , vid) ;
476
494
match self . infcx . probe_const_var ( vid) {
477
495
Ok ( c) => {
0 commit comments