@@ -94,28 +94,6 @@ pub trait Relate<'tcx>: TypeFoldable<TyCtxt<'tcx>> + PartialEq + Copy {
9494///////////////////////////////////////////////////////////////////////////
9595// Relate impls
9696
97- pub fn relate_type_and_mut < ' tcx , R : TypeRelation < ' tcx > > (
98- relation : & mut R ,
99- a : ty:: TypeAndMut < ' tcx > ,
100- b : ty:: TypeAndMut < ' tcx > ,
101- base_ty : Ty < ' tcx > ,
102- ) -> RelateResult < ' tcx , ty:: TypeAndMut < ' tcx > > {
103- debug ! ( "{}.mts({:?}, {:?})" , relation. tag( ) , a, b) ;
104- if a. mutbl != b. mutbl {
105- Err ( TypeError :: Mutability )
106- } else {
107- let mutbl = a. mutbl ;
108- let ( variance, info) = match mutbl {
109- hir:: Mutability :: Not => ( ty:: Covariant , ty:: VarianceDiagInfo :: None ) ,
110- hir:: Mutability :: Mut => {
111- ( ty:: Invariant , ty:: VarianceDiagInfo :: Invariant { ty : base_ty, param_index : 0 } )
112- }
113- } ;
114- let ty = relation. relate_with_variance ( variance, info, a. ty , b. ty ) ?;
115- Ok ( ty:: TypeAndMut { ty, mutbl } )
116- }
117- }
118-
11997#[ inline]
12098pub fn relate_args_invariantly < ' tcx , R : TypeRelation < ' tcx > > (
12199 relation : & mut R ,
@@ -465,17 +443,42 @@ pub fn structurally_relate_tys<'tcx, R: TypeRelation<'tcx>>(
465443 Ok ( Ty :: new_coroutine_closure ( tcx, a_id, args) )
466444 }
467445
468- ( & ty:: RawPtr ( a_mt) , & ty:: RawPtr ( b_mt) ) => {
469- let mt = relate_type_and_mut ( relation, a_mt, b_mt, a) ?;
470- Ok ( Ty :: new_ptr ( tcx, mt) )
446+ (
447+ & ty:: RawPtr ( ty:: TypeAndMut { ty : a_ty, mutbl : a_mutbl } ) ,
448+ & ty:: RawPtr ( ty:: TypeAndMut { ty : b_ty, mutbl : b_mutbl } ) ,
449+ ) => {
450+ if a_mutbl != b_mutbl {
451+ return Err ( TypeError :: Mutability ) ;
452+ }
453+
454+ let ( variance, info) = match a_mutbl {
455+ hir:: Mutability :: Not => ( ty:: Covariant , ty:: VarianceDiagInfo :: None ) ,
456+ hir:: Mutability :: Mut => {
457+ ( ty:: Invariant , ty:: VarianceDiagInfo :: Invariant { ty : a, param_index : 0 } )
458+ }
459+ } ;
460+
461+ let ty = relation. relate_with_variance ( variance, info, a_ty, b_ty) ?;
462+
463+ Ok ( Ty :: new_ptr ( tcx, ty:: TypeAndMut { mutbl : a_mutbl, ty } ) )
471464 }
472465
473466 ( & ty:: Ref ( a_r, a_ty, a_mutbl) , & ty:: Ref ( b_r, b_ty, b_mutbl) ) => {
467+ if a_mutbl != b_mutbl {
468+ return Err ( TypeError :: Mutability ) ;
469+ }
470+
471+ let ( variance, info) = match a_mutbl {
472+ hir:: Mutability :: Not => ( ty:: Covariant , ty:: VarianceDiagInfo :: None ) ,
473+ hir:: Mutability :: Mut => {
474+ ( ty:: Invariant , ty:: VarianceDiagInfo :: Invariant { ty : a, param_index : 0 } )
475+ }
476+ } ;
477+
474478 let r = relation. relate ( a_r, b_r) ?;
475- let a_mt = ty:: TypeAndMut { ty : a_ty, mutbl : a_mutbl } ;
476- let b_mt = ty:: TypeAndMut { ty : b_ty, mutbl : b_mutbl } ;
477- let mt = relate_type_and_mut ( relation, a_mt, b_mt, a) ?;
478- Ok ( Ty :: new_ref ( tcx, r, mt) )
479+ let ty = relation. relate_with_variance ( variance, info, a_ty, b_ty) ?;
480+
481+ Ok ( Ty :: new_ref ( tcx, r, ty:: TypeAndMut { mutbl : a_mutbl, ty } ) )
479482 }
480483
481484 ( & ty:: Array ( a_t, sz_a) , & ty:: Array ( b_t, sz_b) ) => {
0 commit comments