@@ -376,9 +376,18 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'cx, 'tcx> {
376376 }
377377 }
378378
379- fn fold_ty ( & mut self , t : Ty < ' tcx > ) -> Ty < ' tcx > {
379+ fn fold_ty ( & mut self , mut t : Ty < ' tcx > ) -> Ty < ' tcx > {
380380 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+
382391 debug ! ( "canonical: type var found with vid {:?}" , vid) ;
383392 match self . infcx . probe_ty_var ( vid) {
384393 // `t` could be a float / int variable; canonicalize that instead.
@@ -469,9 +478,18 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'cx, 'tcx> {
469478 }
470479 }
471480
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 > {
473482 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+
475493 debug ! ( "canonical: const var found with vid {:?}" , vid) ;
476494 match self . infcx . probe_const_var ( vid) {
477495 Ok ( c) => {
0 commit comments