@@ -28,6 +28,7 @@ use crate::ty::fold::{TypeFoldable, TypeVisitor};
28
28
use crate :: ty:: relate:: { self , Relate , RelateResult , TypeRelation } ;
29
29
use crate :: ty:: subst:: GenericArg ;
30
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).
@@ -629,6 +630,7 @@ where
629
630
// Forbid inference variables in the RHS.
630
631
bug ! ( "unexpected inference var {:?}" , b)
631
632
}
633
+ // FIXME(invariance): see the related FIXME above.
632
634
_ => self . infcx . super_combine_consts ( self , a, b)
633
635
}
634
636
}
@@ -997,11 +999,24 @@ where
997
999
_: & ' tcx ty:: Const < ' tcx > ,
998
1000
) -> RelateResult < ' tcx , & ' tcx ty:: Const < ' tcx > > {
999
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
+ }
1000
1008
ConstValue :: Infer ( InferConst :: Var ( vid) ) => {
1001
1009
let mut variable_table = self . infcx . const_unification_table . borrow_mut ( ) ;
1002
- match variable_table. probe_value ( vid) . val . known ( ) {
1010
+ let var_value = variable_table. probe_value ( vid) ;
1011
+ match var_value. val . known ( ) {
1003
1012
Some ( u) => self . relate ( & u, & u) ,
1004
- None => Ok ( a) ,
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
+ }
1005
1020
}
1006
1021
}
1007
1022
_ => relate:: super_relate_consts ( self , a, a) ,
0 commit comments