@@ -27,7 +27,8 @@ 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
+ use crate :: infer:: { ConstVariableValue , ConstVarValue } ;
31
32
use crate :: mir:: interpret:: ConstValue ;
32
33
use rustc_data_structures:: fx:: FxHashMap ;
33
34
use std:: fmt:: Debug ;
@@ -324,7 +325,7 @@ where
324
325
let vid = pair. vid ( ) ;
325
326
let value_ty = pair. value_ty ( ) ;
326
327
327
- // FIXME -- this logic assumes invariance, but that is wrong.
328
+ // FIXME(invariance) -- this logic assumes invariance, but that is wrong.
328
329
// This only presently applies to chalk integration, as NLL
329
330
// doesn't permit type variables to appear on both sides (and
330
331
// doesn't use lazy norm).
@@ -616,15 +617,21 @@ where
616
617
fn consts (
617
618
& mut self ,
618
619
a : & ' tcx ty:: Const < ' tcx > ,
619
- b : & ' tcx ty:: Const < ' tcx > ,
620
+ mut b : & ' tcx ty:: Const < ' tcx > ,
620
621
) -> 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)
622
+ let a = self . infcx . shallow_resolve ( a) ;
623
+
624
+ if !D :: forbid_inference_vars ( ) {
625
+ b = self . infcx . shallow_resolve ( b) ;
626
+ }
627
+
628
+ match b. val {
629
+ ConstValue :: Infer ( InferConst :: Var ( _) ) if D :: forbid_inference_vars ( ) => {
630
+ // Forbid inference variables in the RHS.
631
+ bug ! ( "unexpected inference var {:?}" , b)
632
+ }
633
+ // FIXME(invariance): see the related FIXME above.
634
+ _ => self . infcx . super_combine_consts ( self , a, b)
628
635
}
629
636
}
630
637
@@ -991,15 +998,28 @@ where
991
998
a : & ' tcx ty:: Const < ' tcx > ,
992
999
_: & ' tcx ty:: Const < ' tcx > ,
993
1000
) -> 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)
1001
+ match a. val {
1002
+ ConstValue :: Infer ( InferConst :: Var ( _) ) if D :: forbid_inference_vars ( ) => {
1003
+ bug ! (
1004
+ "unexpected inference variable encountered in NLL generalization: {:?}" ,
1005
+ a
1006
+ ) ;
1007
+ }
1008
+ ConstValue :: Infer ( InferConst :: Var ( vid) ) => {
1009
+ let mut variable_table = self . infcx . const_unification_table . borrow_mut ( ) ;
1010
+ let var_value = variable_table. probe_value ( vid) ;
1011
+ match var_value. val . known ( ) {
1012
+ Some ( u) => self . relate ( & u, & u) ,
1013
+ None => {
1014
+ let new_var_id = variable_table. new_key ( ConstVarValue {
1015
+ origin : var_value. origin ,
1016
+ val : ConstVariableValue :: Unknown { universe : self . universe } ,
1017
+ } ) ;
1018
+ Ok ( self . tcx ( ) . mk_const_var ( new_var_id, a. ty ) )
1019
+ }
1020
+ }
1021
+ }
1022
+ _ => relate:: super_relate_consts ( self , a, a) ,
1003
1023
}
1004
1024
}
1005
1025
0 commit comments