@@ -28,6 +28,7 @@ use crate::ty::fold::{TypeFoldable, TypeVisitor};
2828use crate :: ty:: relate:: { self , Relate , RelateResult , TypeRelation } ;
2929use crate :: ty:: subst:: GenericArg ;
3030use crate :: ty:: { self , Ty , TyCtxt , InferConst } ;
31+ use crate :: infer:: { ConstVariableValue , ConstVarValue } ;
3132use crate :: mir:: interpret:: ConstValue ;
3233use rustc_data_structures:: fx:: FxHashMap ;
3334use std:: fmt:: Debug ;
@@ -324,7 +325,7 @@ where
324325 let vid = pair. vid ( ) ;
325326 let value_ty = pair. value_ty ( ) ;
326327
327- // FIXME -- this logic assumes invariance, but that is wrong.
328+ // FIXME(invariance) -- this logic assumes invariance, but that is wrong.
328329 // This only presently applies to chalk integration, as NLL
329330 // doesn't permit type variables to appear on both sides (and
330331 // doesn't use lazy norm).
@@ -629,6 +630,7 @@ where
629630 // Forbid inference variables in the RHS.
630631 bug ! ( "unexpected inference var {:?}" , b)
631632 }
633+ // FIXME(invariance): see the related FIXME above.
632634 _ => self . infcx . super_combine_consts ( self , a, b)
633635 }
634636 }
@@ -997,11 +999,24 @@ where
997999 _: & ' tcx ty:: Const < ' tcx > ,
9981000 ) -> RelateResult < ' tcx , & ' tcx ty:: Const < ' tcx > > {
9991001 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+ }
10001008 ConstValue :: Infer ( InferConst :: Var ( vid) ) => {
10011009 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 ( ) {
10031012 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+ }
10051020 }
10061021 }
10071022 _ => relate:: super_relate_consts ( self , a, a) ,
0 commit comments