@@ -343,7 +343,7 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
343
343
for_vid : ty:: TyVid ,
344
344
dir : RelationDir ,
345
345
) -> RelateResult < ' tcx , Generalization < ' tcx > > {
346
- debug ! ( "generalize(ty={:?}, for_vid={:?}, dir={:?}" , ty, for_vid, dir) ;
346
+ debug ! ( "generalize(ty={:?}, for_vid={:?}, dir={:?}) " , ty, for_vid, dir) ;
347
347
// Determine the ambient variance within which `ty` appears.
348
348
// The surrounding equation is:
349
349
//
@@ -649,13 +649,17 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
649
649
) -> RelateResult < ' tcx , & ' tcx ty:: Const < ' tcx > > {
650
650
assert_eq ! ( c, c2) ; // we are abusing TypeRelation here; both LHS and RHS ought to be ==
651
651
652
+ debug ! ( "generalize: consts c={:?}" , c) ;
652
653
match c. val {
653
654
ty:: ConstKind :: Infer ( InferConst :: Var ( vid) ) => {
654
655
let mut inner = self . infcx . inner . borrow_mut ( ) ;
655
656
let variable_table = & mut inner. const_unification_table ( ) ;
656
657
let var_value = variable_table. probe_value ( vid) ;
657
658
match var_value. val {
658
- ConstVariableValue :: Known { value : u } => self . relate ( & u, & u) ,
659
+ ConstVariableValue :: Known { value : u } => {
660
+ drop ( inner) ;
661
+ self . relate ( & u, & u)
662
+ }
659
663
ConstVariableValue :: Unknown { universe } => {
660
664
if self . for_universe . can_name ( universe) {
661
665
Ok ( c)
@@ -669,7 +673,22 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
669
673
}
670
674
}
671
675
}
672
- ty:: ConstKind :: Unevaluated ( ..) if self . tcx ( ) . lazy_normalization ( ) => Ok ( c) ,
676
+ ty:: ConstKind :: Unevaluated ( did, substs, promoted)
677
+ if self . tcx ( ) . lazy_normalization ( ) =>
678
+ {
679
+ // We have to generalize inference variables used in the generic substitutions,
680
+ // as unevaluated consts may otherwise contain invalid inference variables.
681
+ let new_substs =
682
+ self . relate_with_variance ( ty:: Variance :: Invariant , & substs, & substs) ?;
683
+ if new_substs != substs {
684
+ Ok ( self . tcx ( ) . mk_const ( ty:: Const {
685
+ ty : c. ty ,
686
+ val : ty:: ConstKind :: Unevaluated ( did, new_substs, promoted) ,
687
+ } ) )
688
+ } else {
689
+ Ok ( c)
690
+ }
691
+ }
673
692
_ => relate:: super_relate_consts ( self , c, c) ,
674
693
}
675
694
}
0 commit comments