@@ -27,6 +27,7 @@ use super::generalize::{self, CombineDelegate, Generalization};
27
27
use super :: glb:: Glb ;
28
28
use super :: lub:: Lub ;
29
29
use super :: sub:: Sub ;
30
+ use super :: StructurallyRelateAliases ;
30
31
use crate :: infer:: { DefineOpaqueTypes , InferCtxt , TypeTrace } ;
31
32
use crate :: traits:: { Obligation , PredicateObligations } ;
32
33
use rustc_middle:: infer:: canonical:: OriginalQueryValues ;
@@ -48,9 +49,10 @@ pub struct CombineFields<'infcx, 'tcx> {
48
49
}
49
50
50
51
impl < ' tcx > InferCtxt < ' tcx > {
51
- pub fn super_combine_tys < R > (
52
+ pub ( super ) fn super_combine_tys < R > (
52
53
& self ,
53
54
relation : & mut R ,
55
+ structurally_relate_aliases : StructurallyRelateAliases ,
54
56
a : Ty < ' tcx > ,
55
57
b : Ty < ' tcx > ,
56
58
) -> RelateResult < ' tcx , Ty < ' tcx > >
@@ -117,8 +119,15 @@ impl<'tcx> InferCtxt<'tcx> {
117
119
}
118
120
119
121
( _, ty:: Alias ( ..) ) | ( ty:: Alias ( ..) , _) if self . next_trait_solver ( ) => {
120
- relation. register_type_relate_obligation ( a, b) ;
121
- Ok ( a)
122
+ match structurally_relate_aliases {
123
+ StructurallyRelateAliases :: Yes => {
124
+ ty:: relate:: structurally_relate_tys ( relation, a, b)
125
+ }
126
+ StructurallyRelateAliases :: No => {
127
+ relation. register_type_relate_obligation ( a, b) ;
128
+ Ok ( a)
129
+ }
130
+ }
122
131
}
123
132
124
133
// All other cases of inference are errors
@@ -139,9 +148,10 @@ impl<'tcx> InferCtxt<'tcx> {
139
148
}
140
149
}
141
150
142
- pub fn super_combine_consts < R > (
151
+ pub ( super ) fn super_combine_consts < R > (
143
152
& self ,
144
153
relation : & mut R ,
154
+ structurally_relate_aliases : StructurallyRelateAliases ,
145
155
a : ty:: Const < ' tcx > ,
146
156
b : ty:: Const < ' tcx > ,
147
157
) -> RelateResult < ' tcx , ty:: Const < ' tcx > >
@@ -225,11 +235,21 @@ impl<'tcx> InferCtxt<'tcx> {
225
235
}
226
236
227
237
( ty:: ConstKind :: Infer ( InferConst :: Var ( vid) ) , _) => {
228
- return self . unify_const_variable ( vid, b, relation. param_env ( ) ) ;
238
+ return self . unify_const_variable (
239
+ structurally_relate_aliases,
240
+ relation. param_env ( ) ,
241
+ vid,
242
+ b,
243
+ ) ;
229
244
}
230
245
231
246
( _, ty:: ConstKind :: Infer ( InferConst :: Var ( vid) ) ) => {
232
- return self . unify_const_variable ( vid, a, relation. param_env ( ) ) ;
247
+ return self . unify_const_variable (
248
+ structurally_relate_aliases,
249
+ relation. param_env ( ) ,
250
+ vid,
251
+ a,
252
+ ) ;
233
253
}
234
254
235
255
( ty:: ConstKind :: Infer ( InferConst :: EffectVar ( vid) ) , _) => {
@@ -308,9 +328,10 @@ impl<'tcx> InferCtxt<'tcx> {
308
328
#[ instrument( level = "debug" , skip( self ) ) ]
309
329
fn unify_const_variable (
310
330
& self ,
331
+ structurally_relate_aliases : StructurallyRelateAliases ,
332
+ param_env : ty:: ParamEnv < ' tcx > ,
311
333
target_vid : ty:: ConstVid ,
312
334
ct : ty:: Const < ' tcx > ,
313
- param_env : ty:: ParamEnv < ' tcx > ,
314
335
) -> RelateResult < ' tcx , ty:: Const < ' tcx > > {
315
336
let span = match self . inner . borrow_mut ( ) . const_unification_table ( ) . probe_value ( target_vid) {
316
337
ConstVariableValue :: Known { value } => {
@@ -323,6 +344,7 @@ impl<'tcx> InferCtxt<'tcx> {
323
344
let Generalization { value_may_be_infer : value, needs_wf : _ } = generalize:: generalize (
324
345
self ,
325
346
& mut CombineDelegate { infcx : self , span } ,
347
+ structurally_relate_aliases,
326
348
ct,
327
349
target_vid,
328
350
ty:: Variance :: Invariant ,
@@ -335,7 +357,7 @@ impl<'tcx> InferCtxt<'tcx> {
335
357
Ok ( value)
336
358
}
337
359
338
- fn unify_integral_variable (
360
+ pub ( super ) fn unify_integral_variable (
339
361
& self ,
340
362
vid_is_expected : bool ,
341
363
vid : ty:: IntVid ,
@@ -352,7 +374,7 @@ impl<'tcx> InferCtxt<'tcx> {
352
374
}
353
375
}
354
376
355
- fn unify_float_variable (
377
+ pub ( super ) fn unify_float_variable (
356
378
& self ,
357
379
vid_is_expected : bool ,
358
380
vid : ty:: FloatVid ,
@@ -366,7 +388,7 @@ impl<'tcx> InferCtxt<'tcx> {
366
388
Ok ( Ty :: new_float ( self . tcx , val) )
367
389
}
368
390
369
- fn unify_effect_variable (
391
+ pub ( super ) fn unify_effect_variable (
370
392
& self ,
371
393
vid_is_expected : bool ,
372
394
vid : ty:: EffectVid ,
@@ -414,6 +436,7 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
414
436
#[ instrument( skip( self ) , level = "debug" ) ]
415
437
pub fn instantiate (
416
438
& mut self ,
439
+ structurally_relate_aliases : StructurallyRelateAliases ,
417
440
a_ty : Ty < ' tcx > ,
418
441
ambient_variance : ty:: Variance ,
419
442
b_vid : ty:: TyVid ,
@@ -436,6 +459,7 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
436
459
let Generalization { value_may_be_infer : b_ty, needs_wf } = generalize:: generalize (
437
460
self . infcx ,
438
461
& mut CombineDelegate { infcx : self . infcx , span : self . trace . span ( ) } ,
462
+ structurally_relate_aliases,
439
463
a_ty,
440
464
b_vid,
441
465
ambient_variance,
@@ -564,23 +588,23 @@ pub trait ObligationEmittingRelation<'tcx>: TypeRelation<'tcx> {
564
588
fn alias_relate_direction ( & self ) -> ty:: AliasRelationDirection ;
565
589
}
566
590
567
- fn int_unification_error < ' tcx > (
591
+ pub ( super ) fn int_unification_error < ' tcx > (
568
592
a_is_expected : bool ,
569
593
v : ( ty:: IntVarValue , ty:: IntVarValue ) ,
570
594
) -> TypeError < ' tcx > {
571
595
let ( a, b) = v;
572
596
TypeError :: IntMismatch ( ExpectedFound :: new ( a_is_expected, a, b) )
573
597
}
574
598
575
- fn float_unification_error < ' tcx > (
599
+ pub ( super ) fn float_unification_error < ' tcx > (
576
600
a_is_expected : bool ,
577
601
v : ( ty:: FloatVarValue , ty:: FloatVarValue ) ,
578
602
) -> TypeError < ' tcx > {
579
603
let ( ty:: FloatVarValue ( a) , ty:: FloatVarValue ( b) ) = v;
580
604
TypeError :: FloatMismatch ( ExpectedFound :: new ( a_is_expected, a, b) )
581
605
}
582
606
583
- fn effect_unification_error < ' tcx > (
607
+ pub ( super ) fn effect_unification_error < ' tcx > (
584
608
_tcx : TyCtxt < ' tcx > ,
585
609
_a_is_expected : bool ,
586
610
( _a, _b) : ( EffectVarValue < ' tcx > , EffectVarValue < ' tcx > ) ,
0 commit comments