@@ -27,7 +27,7 @@ use crate::ty::error::TypeError;
27
27
use crate :: ty:: fold:: { TypeFoldable , TypeVisitor } ;
28
28
use crate :: ty:: relate:: { self , Relate , RelateResult , TypeRelation } ;
29
29
use crate :: ty:: subst:: GenericArg ;
30
- use crate :: ty:: { self , Ty , TyCtxt } ;
30
+ use crate :: ty:: { self , Ty , TyCtxt , InferConst } ;
31
31
use crate :: mir:: interpret:: ConstValue ;
32
32
use rustc_data_structures:: fx:: FxHashMap ;
33
33
use std:: fmt:: Debug ;
@@ -616,15 +616,20 @@ where
616
616
fn consts (
617
617
& mut self ,
618
618
a : & ' tcx ty:: Const < ' tcx > ,
619
- b : & ' tcx ty:: Const < ' tcx > ,
619
+ mut b : & ' tcx ty:: Const < ' tcx > ,
620
620
) -> 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)
628
633
}
629
634
}
630
635
@@ -991,15 +996,15 @@ where
991
996
a : & ' tcx ty:: Const < ' tcx > ,
992
997
_: & ' tcx ty:: Const < ' tcx > ,
993
998
) -> 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) ,
1003
1008
}
1004
1009
}
1005
1010
0 commit comments