@@ -51,6 +51,30 @@ pub trait TypeRelation<'a, 'gcx: 'a+'tcx, 'tcx: 'a> : Sized {
51
51
Relate :: relate ( self , a, b)
52
52
}
53
53
54
+ /// Relate the two substitutions for the given item. The default
55
+ /// is to look up the variance for the item and proceed
56
+ /// accordingly.
57
+ fn relate_item_substs ( & mut self ,
58
+ item_def_id : DefId ,
59
+ a_subst : & ' tcx Substs < ' tcx > ,
60
+ b_subst : & ' tcx Substs < ' tcx > )
61
+ -> RelateResult < ' tcx , & ' tcx Substs < ' tcx > >
62
+ {
63
+ debug ! ( "relate_item_substs(item_def_id={:?}, a_subst={:?}, b_subst={:?})" ,
64
+ item_def_id,
65
+ a_subst,
66
+ b_subst) ;
67
+
68
+ let variances;
69
+ let opt_variances = if self . tcx ( ) . variance_computed . get ( ) {
70
+ variances = self . tcx ( ) . item_variances ( item_def_id) ;
71
+ Some ( & * variances)
72
+ } else {
73
+ None
74
+ } ;
75
+ relate_substs ( self , opt_variances, a_subst, b_subst)
76
+ }
77
+
54
78
/// Switch variance for the purpose of relating `a` and `b`.
55
79
fn relate_with_variance < T : Relate < ' tcx > > ( & mut self ,
56
80
variance : ty:: Variance ,
@@ -109,31 +133,6 @@ impl<'tcx> Relate<'tcx> for ty::TypeAndMut<'tcx> {
109
133
}
110
134
}
111
135
112
- // substitutions are not themselves relatable without more context,
113
- // but they is an important subroutine for things that ARE relatable,
114
- // like traits etc.
115
- fn relate_item_substs < ' a , ' gcx , ' tcx , R > ( relation : & mut R ,
116
- item_def_id : DefId ,
117
- a_subst : & ' tcx Substs < ' tcx > ,
118
- b_subst : & ' tcx Substs < ' tcx > )
119
- -> RelateResult < ' tcx , & ' tcx Substs < ' tcx > >
120
- where R : TypeRelation < ' a , ' gcx , ' tcx > , ' gcx : ' a +' tcx , ' tcx : ' a
121
- {
122
- debug ! ( "substs: item_def_id={:?} a_subst={:?} b_subst={:?}" ,
123
- item_def_id,
124
- a_subst,
125
- b_subst) ;
126
-
127
- let variances;
128
- let opt_variances = if relation. tcx ( ) . variance_computed . get ( ) {
129
- variances = relation. tcx ( ) . item_variances ( item_def_id) ;
130
- Some ( & * variances)
131
- } else {
132
- None
133
- } ;
134
- relate_substs ( relation, opt_variances, a_subst, b_subst)
135
- }
136
-
137
136
pub fn relate_substs < ' a , ' gcx , ' tcx , R > ( relation : & mut R ,
138
137
variances : Option < & Vec < ty:: Variance > > ,
139
138
a_subst : & ' tcx Substs < ' tcx > ,
@@ -297,7 +296,7 @@ impl<'tcx> Relate<'tcx> for ty::TraitRef<'tcx> {
297
296
if a. def_id != b. def_id {
298
297
Err ( TypeError :: Traits ( expected_found ( relation, & a. def_id , & b. def_id ) ) )
299
298
} else {
300
- let substs = relate_item_substs ( relation , a. def_id , a. substs , b. substs ) ?;
299
+ let substs = relation . relate_item_substs ( a. def_id , a. substs , b. substs ) ?;
301
300
Ok ( ty:: TraitRef { def_id : a. def_id , substs : substs } )
302
301
}
303
302
}
@@ -314,7 +313,7 @@ impl<'tcx> Relate<'tcx> for ty::ExistentialTraitRef<'tcx> {
314
313
if a. def_id != b. def_id {
315
314
Err ( TypeError :: Traits ( expected_found ( relation, & a. def_id , & b. def_id ) ) )
316
315
} else {
317
- let substs = relate_item_substs ( relation , a. def_id , a. substs , b. substs ) ?;
316
+ let substs = relation . relate_item_substs ( a. def_id , a. substs , b. substs ) ?;
318
317
Ok ( ty:: ExistentialTraitRef { def_id : a. def_id , substs : substs } )
319
318
}
320
319
}
@@ -378,7 +377,7 @@ pub fn super_relate_tys<'a, 'gcx, 'tcx, R>(relation: &mut R,
378
377
( & ty:: TyAdt ( a_def, a_substs) , & ty:: TyAdt ( b_def, b_substs) )
379
378
if a_def == b_def =>
380
379
{
381
- let substs = relate_item_substs ( relation , a_def. did , a_substs, b_substs) ?;
380
+ let substs = relation . relate_item_substs ( a_def. did , a_substs, b_substs) ?;
382
381
Ok ( tcx. mk_adt ( a_def, substs) )
383
382
}
384
383
0 commit comments