@@ -45,7 +45,7 @@ use middle::ty::{IntType, UintType};
4545use middle:: ty:: { self , Ty } ;
4646use middle:: ty:: error:: TypeError ;
4747use middle:: ty:: fold:: { TypeFolder , TypeFoldable } ;
48- use middle:: ty:: relate:: { Relate , RelateResult , TypeRelation } ;
48+ use middle:: ty:: relate:: { Relate , RelateOk , RelateResult , TypeRelation } ;
4949
5050use syntax:: ast;
5151use syntax:: codemap:: Span ;
@@ -74,7 +74,7 @@ pub fn super_combine_tys<'a,'tcx:'a,R>(infcx: &InferCtxt<'a, 'tcx>,
7474 . borrow_mut ( )
7575 . unify_var_var ( a_id, b_id)
7676 . map_err ( |e| int_unification_error ( a_is_expected, e) ) ) ;
77- Ok ( a )
77+ Ok ( RelateOk :: from ( a ) )
7878 }
7979 ( & ty:: TyInfer ( ty:: IntVar ( v_id) ) , & ty:: TyInt ( v) ) => {
8080 unify_integral_variable ( infcx, a_is_expected, v_id, IntType ( v) )
@@ -95,7 +95,7 @@ pub fn super_combine_tys<'a,'tcx:'a,R>(infcx: &InferCtxt<'a, 'tcx>,
9595 . borrow_mut ( )
9696 . unify_var_var ( a_id, b_id)
9797 . map_err ( |e| float_unification_error ( relation. a_is_expected ( ) , e) ) ) ;
98- Ok ( a )
98+ Ok ( RelateOk :: from ( a ) )
9999 }
100100 ( & ty:: TyInfer ( ty:: FloatVar ( v_id) ) , & ty:: TyFloat ( v) ) => {
101101 unify_float_variable ( infcx, a_is_expected, v_id, v)
@@ -129,8 +129,8 @@ fn unify_integral_variable<'a,'tcx>(infcx: &InferCtxt<'a,'tcx>,
129129 . unify_var_value ( vid, val)
130130 . map_err ( |e| int_unification_error ( vid_is_expected, e) ) ) ;
131131 match val {
132- IntType ( v) => Ok ( infcx. tcx . mk_mach_int ( v) ) ,
133- UintType ( v) => Ok ( infcx. tcx . mk_mach_uint ( v) ) ,
132+ IntType ( v) => Ok ( RelateOk :: from ( infcx. tcx . mk_mach_int ( v) ) ) ,
133+ UintType ( v) => Ok ( RelateOk :: from ( infcx. tcx . mk_mach_uint ( v) ) ) ,
134134 }
135135}
136136
@@ -145,7 +145,7 @@ fn unify_float_variable<'a,'tcx>(infcx: &InferCtxt<'a,'tcx>,
145145 . borrow_mut ( )
146146 . unify_var_value ( vid, val)
147147 . map_err ( |e| float_unification_error ( vid_is_expected, e) ) ) ;
148- Ok ( infcx. tcx . mk_mach_float ( val) )
148+ Ok ( RelateOk :: from ( infcx. tcx . mk_mach_float ( val) ) )
149149}
150150
151151impl < ' a , ' tcx > CombineFields < ' a , ' tcx > {
@@ -187,6 +187,7 @@ impl<'a, 'tcx> CombineFields<'a, 'tcx> {
187187 -> RelateResult < ' tcx , ( ) >
188188 {
189189 let mut stack = Vec :: new ( ) ;
190+ let mut obligations = Vec :: new ( ) ;
190191 stack. push ( ( a_ty, dir, b_vid) ) ;
191192 loop {
192193 // For each turn of the loop, we extract a tuple
@@ -224,10 +225,11 @@ impl<'a, 'tcx> CombineFields<'a, 'tcx> {
224225 Some ( t) => t, // ...already instantiated.
225226 None => { // ...not yet instantiated:
226227 // Generalize type if necessary.
227- let generalized_ty = try!( match dir {
228- EqTo => self . generalize ( a_ty, b_vid, false ) ,
229- BiTo | SupertypeOf | SubtypeOf => self . generalize ( a_ty, b_vid, true ) ,
230- } ) ;
228+ let RelateOk { value : generalized_ty, obligations : new_obligations } =
229+ try!( match dir {
230+ EqTo => self . generalize ( a_ty, b_vid, false ) ,
231+ BiTo | SupertypeOf | SubtypeOf => self . generalize ( a_ty, b_vid, true ) ,
232+ } ) ;
231233 debug ! ( "instantiate(a_ty={:?}, dir={:?}, \
232234 b_vid={:?}, generalized_ty={:?})",
233235 a_ty, dir, b_vid,
@@ -236,6 +238,7 @@ impl<'a, 'tcx> CombineFields<'a, 'tcx> {
236238 . borrow_mut ( )
237239 . instantiate_and_push (
238240 b_vid, generalized_ty, & mut stack) ;
241+ obligations. extend ( new_obligations) ;
239242 generalized_ty
240243 }
241244 } ;
@@ -247,15 +250,16 @@ impl<'a, 'tcx> CombineFields<'a, 'tcx> {
247250 // relations wind up attributed to the same spans. We need
248251 // to associate causes/spans with each of the relations in
249252 // the stack to get this right.
250- try!( match dir {
253+ let RelateOk { obligations : new_obligations , .. } = try!( match dir {
251254 BiTo => self . bivariate ( ) . relate ( & a_ty, & b_ty) ,
252255 EqTo => self . equate ( ) . relate ( & a_ty, & b_ty) ,
253256 SubtypeOf => self . sub ( ) . relate ( & a_ty, & b_ty) ,
254257 SupertypeOf => self . sub ( ) . relate_with_variance ( ty:: Contravariant , & a_ty, & b_ty) ,
255258 } ) ;
259+ obligations. extend ( new_obligations) ;
256260 }
257261
258- Ok ( ( ) )
262+ Ok ( RelateOk { value : ( ) , obligations : obligations } )
259263 }
260264
261265 /// Attempts to generalize `ty` for the type variable `for_vid`. This checks for cycle -- that
@@ -279,7 +283,7 @@ impl<'a, 'tcx> CombineFields<'a, 'tcx> {
279283 if generalize. cycle_detected {
280284 Err ( TypeError :: CyclicTy )
281285 } else {
282- Ok ( u )
286+ Ok ( RelateOk :: from ( u ) )
283287 }
284288 }
285289}
@@ -370,7 +374,7 @@ impl<'tcx, T:Clone + PartialEq> RelateResultCompare<'tcx, T> for RelateResult<'t
370374 F : FnOnce ( ) -> TypeError < ' tcx > ,
371375 {
372376 self . clone ( ) . and_then ( |s| {
373- if s == t {
377+ if s. value == t {
374378 self . clone ( )
375379 } else {
376380 Err ( f ( ) )
0 commit comments