@@ -30,7 +30,7 @@ use super::{DefineOpaqueTypes, InferCtxt, TypeTrace};
3030use  crate :: infer:: generalize:: { self ,  CombineDelegate ,  Generalization } ; 
3131use  crate :: traits:: { Obligation ,  PredicateObligations } ; 
3232use  rustc_middle:: infer:: canonical:: OriginalQueryValues ; 
33- use  rustc_middle:: infer:: unify_key:: { ConstVarValue ,  ConstVariableValue } ; 
33+ use  rustc_middle:: infer:: unify_key:: { ConstVarValue ,  ConstVariableValue ,   EffectVarValue } ; 
3434use  rustc_middle:: infer:: unify_key:: { ConstVariableOrigin ,  ConstVariableOriginKind } ; 
3535use  rustc_middle:: ty:: error:: { ExpectedFound ,  TypeError } ; 
3636use  rustc_middle:: ty:: relate:: { RelateResult ,  TypeRelation } ; 
@@ -91,7 +91,7 @@ impl<'tcx> InferCtxt<'tcx> {
9191                    . borrow_mut ( ) 
9292                    . float_unification_table ( ) 
9393                    . unify_var_var ( a_id,  b_id) 
94-                     . map_err ( |e| float_unification_error ( relation . a_is_expected ( ) ,  e) ) ?; 
94+                     . map_err ( |e| float_unification_error ( a_is_expected,  e) ) ?; 
9595                Ok ( a) 
9696            } 
9797            ( & ty:: Infer ( ty:: FloatVar ( v_id) ) ,  & ty:: Float ( v) )  => { 
@@ -210,10 +210,30 @@ impl<'tcx> InferCtxt<'tcx> {
210210                return  Ok ( a) ; 
211211            } 
212212
213+             ( 
214+                 ty:: ConstKind :: Infer ( InferConst :: EffectVar ( a_vid) ) , 
215+                 ty:: ConstKind :: Infer ( InferConst :: EffectVar ( b_vid) ) , 
216+             )  => { 
217+                 self . inner 
218+                     . borrow_mut ( ) 
219+                     . effect_unification_table ( ) 
220+                     . unify_var_var ( a_vid,  b_vid) 
221+                     . map_err ( |a| effect_unification_error ( self . tcx ,  relation. a_is_expected ( ) ,  a) ) ?; 
222+                 return  Ok ( a) ; 
223+             } 
224+ 
213225            // All other cases of inference with other variables are errors. 
214-             ( ty:: ConstKind :: Infer ( InferConst :: Var ( _) ) ,  ty:: ConstKind :: Infer ( _) ) 
215-             | ( ty:: ConstKind :: Infer ( _) ,  ty:: ConstKind :: Infer ( InferConst :: Var ( _) ) )  => { 
216-                 bug ! ( "tried to combine ConstKind::Infer/ConstKind::Infer(InferConst::Var)" ) 
226+             ( 
227+                 ty:: ConstKind :: Infer ( InferConst :: Var ( _)  | InferConst :: EffectVar ( _) ) , 
228+                 ty:: ConstKind :: Infer ( _) , 
229+             ) 
230+             | ( 
231+                 ty:: ConstKind :: Infer ( _) , 
232+                 ty:: ConstKind :: Infer ( InferConst :: Var ( _)  | InferConst :: EffectVar ( _) ) , 
233+             )  => { 
234+                 bug ! ( 
235+                     "tried to combine ConstKind::Infer/ConstKind::Infer(InferConst::Var): {a:?} and {b:?}" 
236+                 ) 
217237            } 
218238
219239            ( ty:: ConstKind :: Infer ( InferConst :: Var ( vid) ) ,  _)  => { 
@@ -223,6 +243,23 @@ impl<'tcx> InferCtxt<'tcx> {
223243            ( _,  ty:: ConstKind :: Infer ( InferConst :: Var ( vid) ) )  => { 
224244                return  self . unify_const_variable ( vid,  a,  relation. param_env ( ) ) ; 
225245            } 
246+ 
247+             ( ty:: ConstKind :: Infer ( InferConst :: EffectVar ( vid) ) ,  _)  => { 
248+                 return  self . unify_effect_variable ( 
249+                     relation. a_is_expected ( ) , 
250+                     vid, 
251+                     EffectVarValue :: Const ( b) , 
252+                 ) ; 
253+             } 
254+ 
255+             ( _,  ty:: ConstKind :: Infer ( InferConst :: EffectVar ( vid) ) )  => { 
256+                 return  self . unify_effect_variable ( 
257+                     !relation. a_is_expected ( ) , 
258+                     vid, 
259+                     EffectVarValue :: Const ( a) , 
260+                 ) ; 
261+             } 
262+ 
226263            ( ty:: ConstKind :: Unevaluated ( ..) ,  _)  | ( _,  ty:: ConstKind :: Unevaluated ( ..) ) 
227264                if  self . tcx . features ( ) . generic_const_exprs  || self . next_trait_solver ( )  =>
228265            { 
@@ -340,6 +377,20 @@ impl<'tcx> InferCtxt<'tcx> {
340377            . map_err ( |e| float_unification_error ( vid_is_expected,  e) ) ?; 
341378        Ok ( Ty :: new_float ( self . tcx ,  val) ) 
342379    } 
380+ 
381+     fn  unify_effect_variable ( 
382+         & self , 
383+         vid_is_expected :  bool , 
384+         vid :  ty:: EffectVid < ' tcx > , 
385+         val :  EffectVarValue < ' tcx > , 
386+     )  -> RelateResult < ' tcx ,  ty:: Const < ' tcx > >  { 
387+         self . inner 
388+             . borrow_mut ( ) 
389+             . effect_unification_table ( ) 
390+             . unify_var_value ( vid,  Some ( val) ) 
391+             . map_err ( |e| effect_unification_error ( self . tcx ,  vid_is_expected,  e) ) ?; 
392+         Ok ( val. as_const ( self . tcx ) ) 
393+     } 
343394} 
344395
345396impl < ' infcx ,  ' tcx >  CombineFields < ' infcx ,  ' tcx >  { 
@@ -493,3 +544,11 @@ fn float_unification_error<'tcx>(
493544    let  ( ty:: FloatVarValue ( a) ,  ty:: FloatVarValue ( b) )  = v; 
494545    TypeError :: FloatMismatch ( ExpectedFound :: new ( a_is_expected,  a,  b) ) 
495546} 
547+ 
548+ fn  effect_unification_error < ' tcx > ( 
549+     tcx :  TyCtxt < ' tcx > , 
550+     a_is_expected :  bool , 
551+     ( a,  b) :  ( EffectVarValue < ' tcx > ,  EffectVarValue < ' tcx > ) , 
552+ )  -> TypeError < ' tcx >  { 
553+     TypeError :: ConstMismatch ( ExpectedFound :: new ( a_is_expected,  a. as_const ( tcx) ,  b. as_const ( tcx) ) ) 
554+ } 
0 commit comments