@@ -30,7 +30,7 @@ use super::{DefineOpaqueTypes, InferCtxt, TypeTrace};
30
30
use crate :: infer:: generalize:: { self , CombineDelegate , Generalization } ;
31
31
use crate :: traits:: { Obligation , PredicateObligations } ;
32
32
use rustc_middle:: infer:: canonical:: OriginalQueryValues ;
33
- use rustc_middle:: infer:: unify_key:: { ConstVarValue , ConstVariableValue } ;
33
+ use rustc_middle:: infer:: unify_key:: { ConstVarValue , ConstVariableValue , EffectVarValue } ;
34
34
use rustc_middle:: infer:: unify_key:: { ConstVariableOrigin , ConstVariableOriginKind } ;
35
35
use rustc_middle:: ty:: error:: { ExpectedFound , TypeError } ;
36
36
use rustc_middle:: ty:: relate:: { RelateResult , TypeRelation } ;
@@ -91,7 +91,7 @@ impl<'tcx> InferCtxt<'tcx> {
91
91
. borrow_mut ( )
92
92
. float_unification_table ( )
93
93
. 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) ) ?;
95
95
Ok ( a)
96
96
}
97
97
( & ty:: Infer ( ty:: FloatVar ( v_id) ) , & ty:: Float ( v) ) => {
@@ -210,10 +210,30 @@ impl<'tcx> InferCtxt<'tcx> {
210
210
return Ok ( a) ;
211
211
}
212
212
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
+
213
225
// 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
+ )
217
237
}
218
238
219
239
( ty:: ConstKind :: Infer ( InferConst :: Var ( vid) ) , _) => {
@@ -223,6 +243,23 @@ impl<'tcx> InferCtxt<'tcx> {
223
243
( _, ty:: ConstKind :: Infer ( InferConst :: Var ( vid) ) ) => {
224
244
return self . unify_const_variable ( vid, a, relation. param_env ( ) ) ;
225
245
}
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
+
226
263
( ty:: ConstKind :: Unevaluated ( ..) , _) | ( _, ty:: ConstKind :: Unevaluated ( ..) )
227
264
if self . tcx . features ( ) . generic_const_exprs || self . next_trait_solver ( ) =>
228
265
{
@@ -340,6 +377,20 @@ impl<'tcx> InferCtxt<'tcx> {
340
377
. map_err ( |e| float_unification_error ( vid_is_expected, e) ) ?;
341
378
Ok ( Ty :: new_float ( self . tcx , val) )
342
379
}
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
+ }
343
394
}
344
395
345
396
impl < ' infcx , ' tcx > CombineFields < ' infcx , ' tcx > {
@@ -493,3 +544,11 @@ fn float_unification_error<'tcx>(
493
544
let ( ty:: FloatVarValue ( a) , ty:: FloatVarValue ( b) ) = v;
494
545
TypeError :: FloatMismatch ( ExpectedFound :: new ( a_is_expected, a, b) )
495
546
}
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