@@ -67,6 +67,7 @@ pub trait TypeRelation<'tcx>: Sized {
67
67
fn relate_with_variance < T : Relate < ' tcx > > (
68
68
& mut self ,
69
69
variance : ty:: Variance ,
70
+ info : ty:: VarianceDiagInfo < ' tcx > ,
70
71
a : T ,
71
72
b : T ,
72
73
) -> RelateResult < ' tcx , T > ;
@@ -111,24 +112,23 @@ pub trait Relate<'tcx>: TypeFoldable<'tcx> + Copy {
111
112
///////////////////////////////////////////////////////////////////////////
112
113
// Relate impls
113
114
114
- impl < ' tcx > Relate < ' tcx > for ty:: TypeAndMut < ' tcx > {
115
- fn relate < R : TypeRelation < ' tcx > > (
116
- relation : & mut R ,
117
- a : ty:: TypeAndMut < ' tcx > ,
118
- b : ty:: TypeAndMut < ' tcx > ,
119
- ) -> RelateResult < ' tcx , ty:: TypeAndMut < ' tcx > > {
120
- debug ! ( "{}.mts({:?}, {:?})" , relation. tag( ) , a, b) ;
121
- if a. mutbl != b. mutbl {
122
- Err ( TypeError :: Mutability )
123
- } else {
124
- let mutbl = a. mutbl ;
125
- let variance = match mutbl {
126
- ast:: Mutability :: Not => ty:: Covariant ,
127
- ast:: Mutability :: Mut => ty:: Invariant ,
128
- } ;
129
- let ty = relation. relate_with_variance ( variance, a. ty , b. ty ) ?;
130
- Ok ( ty:: TypeAndMut { ty, mutbl } )
131
- }
115
+ fn relate_type_and_mut < ' tcx , R : TypeRelation < ' tcx > > (
116
+ relation : & mut R ,
117
+ a : ty:: TypeAndMut < ' tcx > ,
118
+ b : ty:: TypeAndMut < ' tcx > ,
119
+ kind : ty:: VarianceDiagMutKind ,
120
+ ) -> RelateResult < ' tcx , ty:: TypeAndMut < ' tcx > > {
121
+ debug ! ( "{}.mts({:?}, {:?})" , relation. tag( ) , a, b) ;
122
+ if a. mutbl != b. mutbl {
123
+ Err ( TypeError :: Mutability )
124
+ } else {
125
+ let mutbl = a. mutbl ;
126
+ let ( variance, info) = match mutbl {
127
+ ast:: Mutability :: Not => ( ty:: Covariant , ty:: VarianceDiagInfo :: None ) ,
128
+ ast:: Mutability :: Mut => ( ty:: Invariant , ty:: VarianceDiagInfo :: Mut { kind, ty : a. ty } ) ,
129
+ } ;
130
+ let ty = relation. relate_with_variance ( variance, info, a. ty , b. ty ) ?;
131
+ Ok ( ty:: TypeAndMut { ty, mutbl } )
132
132
}
133
133
}
134
134
@@ -142,7 +142,7 @@ pub fn relate_substs<R: TypeRelation<'tcx>>(
142
142
143
143
let params = iter:: zip ( a_subst, b_subst) . enumerate ( ) . map ( |( i, ( a, b) ) | {
144
144
let variance = variances. map_or ( ty:: Invariant , |v| v[ i] ) ;
145
- relation. relate_with_variance ( variance, a, b)
145
+ relation. relate_with_variance ( variance, ty :: VarianceDiagInfo :: default ( ) , a, b)
146
146
} ) ;
147
147
148
148
tcx. mk_substs ( params)
@@ -177,7 +177,12 @@ impl<'tcx> Relate<'tcx> for ty::FnSig<'tcx> {
177
177
if is_output {
178
178
relation. relate ( a, b)
179
179
} else {
180
- relation. relate_with_variance ( ty:: Contravariant , a, b)
180
+ relation. relate_with_variance (
181
+ ty:: Contravariant ,
182
+ ty:: VarianceDiagInfo :: default ( ) ,
183
+ a,
184
+ b,
185
+ )
181
186
}
182
187
} )
183
188
. enumerate ( )
@@ -251,8 +256,18 @@ impl<'tcx> Relate<'tcx> for ty::ExistentialProjection<'tcx> {
251
256
b. item_def_id ,
252
257
) ) )
253
258
} else {
254
- let ty = relation. relate_with_variance ( ty:: Invariant , a. ty , b. ty ) ?;
255
- let substs = relation. relate_with_variance ( ty:: Invariant , a. substs , b. substs ) ?;
259
+ let ty = relation. relate_with_variance (
260
+ ty:: Invariant ,
261
+ ty:: VarianceDiagInfo :: default ( ) ,
262
+ a. ty ,
263
+ b. ty ,
264
+ ) ?;
265
+ let substs = relation. relate_with_variance (
266
+ ty:: Invariant ,
267
+ ty:: VarianceDiagInfo :: default ( ) ,
268
+ a. substs ,
269
+ b. substs ,
270
+ ) ?;
256
271
Ok ( ty:: ExistentialProjection { item_def_id : a. item_def_id , substs, ty } )
257
272
}
258
273
}
@@ -364,7 +379,12 @@ pub fn super_relate_tys<R: TypeRelation<'tcx>>(
364
379
365
380
( & ty:: Dynamic ( a_obj, a_region) , & ty:: Dynamic ( b_obj, b_region) ) => {
366
381
let region_bound = relation. with_cause ( Cause :: ExistentialRegionBound , |relation| {
367
- relation. relate_with_variance ( ty:: Contravariant , a_region, b_region)
382
+ relation. relate_with_variance (
383
+ ty:: Contravariant ,
384
+ ty:: VarianceDiagInfo :: default ( ) ,
385
+ a_region,
386
+ b_region,
387
+ )
368
388
} ) ?;
369
389
Ok ( tcx. mk_dynamic ( relation. relate ( a_obj, b_obj) ?, region_bound) )
370
390
}
@@ -398,15 +418,20 @@ pub fn super_relate_tys<R: TypeRelation<'tcx>>(
398
418
}
399
419
400
420
( & ty:: RawPtr ( a_mt) , & ty:: RawPtr ( b_mt) ) => {
401
- let mt = relation . relate ( a_mt, b_mt) ?;
421
+ let mt = relate_type_and_mut ( relation , a_mt, b_mt, ty :: VarianceDiagMutKind :: RawPtr ) ?;
402
422
Ok ( tcx. mk_ptr ( mt) )
403
423
}
404
424
405
425
( & ty:: Ref ( a_r, a_ty, a_mutbl) , & ty:: Ref ( b_r, b_ty, b_mutbl) ) => {
406
- let r = relation. relate_with_variance ( ty:: Contravariant , a_r, b_r) ?;
426
+ let r = relation. relate_with_variance (
427
+ ty:: Contravariant ,
428
+ ty:: VarianceDiagInfo :: default ( ) ,
429
+ a_r,
430
+ b_r,
431
+ ) ?;
407
432
let a_mt = ty:: TypeAndMut { ty : a_ty, mutbl : a_mutbl } ;
408
433
let b_mt = ty:: TypeAndMut { ty : b_ty, mutbl : b_mutbl } ;
409
- let mt = relation . relate ( a_mt, b_mt) ?;
434
+ let mt = relate_type_and_mut ( relation , a_mt, b_mt, ty :: VarianceDiagMutKind :: Ref ) ?;
410
435
Ok ( tcx. mk_ref ( r, mt) )
411
436
}
412
437
@@ -536,8 +561,12 @@ pub fn super_relate_consts<R: TypeRelation<'tcx>>(
536
561
( ty:: ConstKind :: Unevaluated ( au) , ty:: ConstKind :: Unevaluated ( bu) )
537
562
if au. def == bu. def && au. promoted == bu. promoted =>
538
563
{
539
- let substs =
540
- relation. relate_with_variance ( ty:: Variance :: Invariant , au. substs , bu. substs ) ?;
564
+ let substs = relation. relate_with_variance (
565
+ ty:: Variance :: Invariant ,
566
+ ty:: VarianceDiagInfo :: default ( ) ,
567
+ au. substs ,
568
+ bu. substs ,
569
+ ) ?;
541
570
return Ok ( tcx. mk_const ( ty:: Const {
542
571
val : ty:: ConstKind :: Unevaluated ( ty:: Unevaluated {
543
572
def : au. def ,
0 commit comments