@@ -51,6 +51,24 @@ pub trait TypeRelation<'a, 'gcx: 'a+'tcx, 'tcx: 'a> : Sized {
5151 Relate :: relate ( self , a, b)
5252 }
5353
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 opt_variances = self . tcx ( ) . variances_of ( item_def_id) ;
69+ relate_substs ( self , Some ( & opt_variances) , a_subst, b_subst)
70+ }
71+
5472 /// Switch variance for the purpose of relating `a` and `b`.
5573 fn relate_with_variance < T : Relate < ' tcx > > ( & mut self ,
5674 variance : ty:: Variance ,
@@ -109,25 +127,6 @@ impl<'tcx> Relate<'tcx> for ty::TypeAndMut<'tcx> {
109127 }
110128}
111129
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 opt_variances = relation. tcx ( ) . variances_of ( item_def_id) ;
128- relate_substs ( relation, Some ( & opt_variances) , a_subst, b_subst)
129- }
130-
131130pub fn relate_substs < ' a , ' gcx , ' tcx , R > ( relation : & mut R ,
132131 variances : Option < & Vec < ty:: Variance > > ,
133132 a_subst : & ' tcx Substs < ' tcx > ,
@@ -291,7 +290,7 @@ impl<'tcx> Relate<'tcx> for ty::TraitRef<'tcx> {
291290 if a. def_id != b. def_id {
292291 Err ( TypeError :: Traits ( expected_found ( relation, & a. def_id , & b. def_id ) ) )
293292 } else {
294- let substs = relate_item_substs ( relation , a. def_id , a. substs , b. substs ) ?;
293+ let substs = relation . relate_item_substs ( a. def_id , a. substs , b. substs ) ?;
295294 Ok ( ty:: TraitRef { def_id : a. def_id , substs : substs } )
296295 }
297296 }
@@ -308,7 +307,7 @@ impl<'tcx> Relate<'tcx> for ty::ExistentialTraitRef<'tcx> {
308307 if a. def_id != b. def_id {
309308 Err ( TypeError :: Traits ( expected_found ( relation, & a. def_id , & b. def_id ) ) )
310309 } else {
311- let substs = relate_item_substs ( relation , a. def_id , a. substs , b. substs ) ?;
310+ let substs = relation . relate_item_substs ( a. def_id , a. substs , b. substs ) ?;
312311 Ok ( ty:: ExistentialTraitRef { def_id : a. def_id , substs : substs } )
313312 }
314313 }
@@ -372,7 +371,7 @@ pub fn super_relate_tys<'a, 'gcx, 'tcx, R>(relation: &mut R,
372371 ( & ty:: TyAdt ( a_def, a_substs) , & ty:: TyAdt ( b_def, b_substs) )
373372 if a_def == b_def =>
374373 {
375- let substs = relate_item_substs ( relation , a_def. did , a_substs, b_substs) ?;
374+ let substs = relation . relate_item_substs ( a_def. did , a_substs, b_substs) ?;
376375 Ok ( tcx. mk_adt ( a_def, substs) )
377376 }
378377
0 commit comments