@@ -27,7 +27,7 @@ use crate::ty::error::TypeError;
2727use crate :: ty:: fold:: { TypeFoldable , TypeVisitor } ;
2828use crate :: ty:: relate:: { self , Relate , RelateResult , TypeRelation } ;
2929use crate :: ty:: subst:: GenericArg ;
30- use crate :: ty:: { self , Ty , TyCtxt } ;
30+ use crate :: ty:: { self , Ty , TyCtxt , InferConst } ;
3131use crate :: mir:: interpret:: ConstValue ;
3232use rustc_data_structures:: fx:: FxHashMap ;
3333use std:: fmt:: Debug ;
@@ -616,15 +616,20 @@ where
616616 fn consts (
617617 & mut self ,
618618 a : & ' tcx ty:: Const < ' tcx > ,
619- b : & ' tcx ty:: Const < ' tcx > ,
619+ mut b : & ' tcx ty:: Const < ' tcx > ,
620620 ) -> RelateResult < ' tcx , & ' tcx ty:: Const < ' tcx > > {
621- if let ty:: Const { val : ConstValue :: Bound ( ..) , .. } = a {
622- // FIXME(const_generics): I'm unsure how this branch should actually be handled,
623- // so this is probably not correct.
624- self . infcx . super_combine_consts ( self , a, b)
625- } else {
626- debug ! ( "consts(a={:?}, b={:?}, variance={:?})" , a, b, self . ambient_variance) ;
627- relate:: super_relate_consts ( self , a, b)
621+ let a = self . infcx . shallow_resolve ( a) ;
622+
623+ if !D :: forbid_inference_vars ( ) {
624+ b = self . infcx . shallow_resolve ( b) ;
625+ }
626+
627+ match b. val {
628+ ConstValue :: Infer ( InferConst :: Var ( _) ) if D :: forbid_inference_vars ( ) => {
629+ // Forbid inference variables in the RHS.
630+ bug ! ( "unexpected inference var {:?}" , b)
631+ }
632+ _ => self . infcx . super_combine_consts ( self , a, b)
628633 }
629634 }
630635
@@ -991,15 +996,15 @@ where
991996 a : & ' tcx ty:: Const < ' tcx > ,
992997 _: & ' tcx ty:: Const < ' tcx > ,
993998 ) -> RelateResult < ' tcx , & ' tcx ty:: Const < ' tcx > > {
994- debug ! ( "TypeGeneralizer::consts(a={:?})" , a ) ;
995-
996- if let ty :: Const { val : ConstValue :: Bound ( .. ) , .. } = a {
997- bug ! (
998- "unexpected inference variable encountered in NLL generalization: {:?}" ,
999- a
1000- ) ;
1001- } else {
1002- relate:: super_relate_consts ( self , a, a)
999+ match a . val {
1000+ ConstValue :: Infer ( InferConst :: Var ( vid ) ) => {
1001+ let mut variable_table = self . infcx . const_unification_table . borrow_mut ( ) ;
1002+ match variable_table . probe_value ( vid ) . val . known ( ) {
1003+ Some ( u ) => self . relate ( & u , & u ) ,
1004+ None => Ok ( a ) ,
1005+ }
1006+ }
1007+ _ => relate:: super_relate_consts ( self , a, a) ,
10031008 }
10041009 }
10051010
0 commit comments