@@ -94,28 +94,6 @@ pub trait Relate<'tcx>: TypeFoldable<TyCtxt<'tcx>> + PartialEq + Copy {
94
94
///////////////////////////////////////////////////////////////////////////
95
95
// Relate impls
96
96
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
-
119
97
#[ inline]
120
98
pub fn relate_args_invariantly < ' tcx , R : TypeRelation < ' tcx > > (
121
99
relation : & mut R ,
@@ -465,17 +443,42 @@ pub fn structurally_relate_tys<'tcx, R: TypeRelation<'tcx>>(
465
443
Ok ( Ty :: new_coroutine_closure ( tcx, a_id, args) )
466
444
}
467
445
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 } ) )
471
464
}
472
465
473
466
( & 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
+
474
478
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 } ) )
479
482
}
480
483
481
484
( & ty:: Array ( a_t, sz_a) , & ty:: Array ( b_t, sz_b) ) => {
0 commit comments