@@ -67,6 +67,7 @@ pub trait TypeRelation<'tcx>: Sized {
6767 fn relate_with_variance < T : Relate < ' tcx > > (
6868 & mut self ,
6969 variance : ty:: Variance ,
70+ info : ty:: VarianceDiagInfo < ' tcx > ,
7071 a : T ,
7172 b : T ,
7273 ) -> RelateResult < ' tcx , T > ;
@@ -111,24 +112,23 @@ pub trait Relate<'tcx>: TypeFoldable<'tcx> + Copy {
111112///////////////////////////////////////////////////////////////////////////
112113// Relate impls
113114
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 } )
132132 }
133133}
134134
@@ -142,7 +142,7 @@ pub fn relate_substs<R: TypeRelation<'tcx>>(
142142
143143 let params = iter:: zip ( a_subst, b_subst) . enumerate ( ) . map ( |( i, ( a, b) ) | {
144144 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)
146146 } ) ;
147147
148148 tcx. mk_substs ( params)
@@ -177,7 +177,12 @@ impl<'tcx> Relate<'tcx> for ty::FnSig<'tcx> {
177177 if is_output {
178178 relation. relate ( a, b)
179179 } 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+ )
181186 }
182187 } )
183188 . enumerate ( )
@@ -251,8 +256,18 @@ impl<'tcx> Relate<'tcx> for ty::ExistentialProjection<'tcx> {
251256 b. item_def_id ,
252257 ) ) )
253258 } 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+ ) ?;
256271 Ok ( ty:: ExistentialProjection { item_def_id : a. item_def_id , substs, ty } )
257272 }
258273 }
@@ -364,7 +379,12 @@ pub fn super_relate_tys<R: TypeRelation<'tcx>>(
364379
365380 ( & ty:: Dynamic ( a_obj, a_region) , & ty:: Dynamic ( b_obj, b_region) ) => {
366381 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+ )
368388 } ) ?;
369389 Ok ( tcx. mk_dynamic ( relation. relate ( a_obj, b_obj) ?, region_bound) )
370390 }
@@ -398,15 +418,20 @@ pub fn super_relate_tys<R: TypeRelation<'tcx>>(
398418 }
399419
400420 ( & 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 ) ?;
402422 Ok ( tcx. mk_ptr ( mt) )
403423 }
404424
405425 ( & 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+ ) ?;
407432 let a_mt = ty:: TypeAndMut { ty : a_ty, mutbl : a_mutbl } ;
408433 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 ) ?;
410435 Ok ( tcx. mk_ref ( r, mt) )
411436 }
412437
@@ -536,8 +561,12 @@ pub fn super_relate_consts<R: TypeRelation<'tcx>>(
536561 ( ty:: ConstKind :: Unevaluated ( au) , ty:: ConstKind :: Unevaluated ( bu) )
537562 if au. def == bu. def && au. promoted == bu. promoted =>
538563 {
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+ ) ?;
541570 return Ok ( tcx. mk_const ( ty:: Const {
542571 val : ty:: ConstKind :: Unevaluated ( ty:: Unevaluated {
543572 def : au. def ,
0 commit comments