@@ -633,4 +633,34 @@ impl<'cx, 'gcx, 'tcx> Canonicalizer<'cx, 'gcx, 'tcx> {
633
633
self . tcx ( ) . mk_ty ( ty:: Bound ( self . binder_index , var. into ( ) ) )
634
634
}
635
635
}
636
+
637
+ /// Given a type variable `const_var` of the given kind, first check
638
+ /// if `const_var` is bound to anything; if so, canonicalize
639
+ /// *that*. Otherwise, create a new canonical variable for
640
+ /// `const_var`.
641
+ fn canonicalize_const_var (
642
+ & mut self ,
643
+ info : CanonicalVarInfo ,
644
+ const_var : & ' tcx ty:: LazyConst < ' tcx >
645
+ ) -> & ' tcx ty:: LazyConst < ' tcx > {
646
+ let infcx = self . infcx . expect ( "encountered const-var without infcx" ) ;
647
+ let bound_to = infcx. resolve_const_var ( const_var) ;
648
+ if bound_to != const_var {
649
+ self . fold_const ( bound_to)
650
+ } else {
651
+ let ty = match const_var {
652
+ ty:: LazyConst :: Unevaluated ( def_id, _) => {
653
+ self . tcx . type_of ( * def_id)
654
+ }
655
+ ty:: LazyConst :: Evaluated ( ty:: Const { ty, .. } ) => ty,
656
+ } ;
657
+ let var = self . canonical_var ( info, const_var. into ( ) ) ;
658
+ self . tcx ( ) . mk_lazy_const (
659
+ ty:: LazyConst :: Evaluated ( ty:: Const {
660
+ val : ConstValue :: Infer ( InferConst :: Canonical ( self . binder_index , var. into ( ) ) ) ,
661
+ ty,
662
+ } )
663
+ )
664
+ }
665
+ }
636
666
}
0 commit comments