@@ -45,7 +45,7 @@ use middle::ty::{IntType, UintType};
45
45
use middle:: ty:: { self , Ty } ;
46
46
use middle:: ty:: error:: TypeError ;
47
47
use middle:: ty:: fold:: { TypeFolder , TypeFoldable } ;
48
- use middle:: ty:: relate:: { Relate , RelateResult , TypeRelation } ;
48
+ use middle:: ty:: relate:: { Relate , RelateOk , RelateResult , TypeRelation } ;
49
49
50
50
use syntax:: ast;
51
51
use syntax:: codemap:: Span ;
@@ -74,7 +74,7 @@ pub fn super_combine_tys<'a,'tcx:'a,R>(infcx: &InferCtxt<'a, 'tcx>,
74
74
. borrow_mut ( )
75
75
. unify_var_var ( a_id, b_id)
76
76
. map_err ( |e| int_unification_error ( a_is_expected, e) ) ) ;
77
- Ok ( a )
77
+ Ok ( RelateOk :: from ( a ) )
78
78
}
79
79
( & ty:: TyInfer ( ty:: IntVar ( v_id) ) , & ty:: TyInt ( v) ) => {
80
80
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>,
95
95
. borrow_mut ( )
96
96
. unify_var_var ( a_id, b_id)
97
97
. map_err ( |e| float_unification_error ( relation. a_is_expected ( ) , e) ) ) ;
98
- Ok ( a )
98
+ Ok ( RelateOk :: from ( a ) )
99
99
}
100
100
( & ty:: TyInfer ( ty:: FloatVar ( v_id) ) , & ty:: TyFloat ( v) ) => {
101
101
unify_float_variable ( infcx, a_is_expected, v_id, v)
@@ -129,8 +129,8 @@ fn unify_integral_variable<'a,'tcx>(infcx: &InferCtxt<'a,'tcx>,
129
129
. unify_var_value ( vid, val)
130
130
. map_err ( |e| int_unification_error ( vid_is_expected, e) ) ) ;
131
131
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) ) ) ,
134
134
}
135
135
}
136
136
@@ -145,7 +145,7 @@ fn unify_float_variable<'a,'tcx>(infcx: &InferCtxt<'a,'tcx>,
145
145
. borrow_mut ( )
146
146
. unify_var_value ( vid, val)
147
147
. 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) ) )
149
149
}
150
150
151
151
impl < ' a , ' tcx > CombineFields < ' a , ' tcx > {
@@ -187,6 +187,7 @@ impl<'a, 'tcx> CombineFields<'a, 'tcx> {
187
187
-> RelateResult < ' tcx , ( ) >
188
188
{
189
189
let mut stack = Vec :: new ( ) ;
190
+ let mut obligations = Vec :: new ( ) ;
190
191
stack. push ( ( a_ty, dir, b_vid) ) ;
191
192
loop {
192
193
// For each turn of the loop, we extract a tuple
@@ -224,10 +225,11 @@ impl<'a, 'tcx> CombineFields<'a, 'tcx> {
224
225
Some ( t) => t, // ...already instantiated.
225
226
None => { // ...not yet instantiated:
226
227
// 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
+ } ) ;
231
233
debug ! ( "instantiate(a_ty={:?}, dir={:?}, \
232
234
b_vid={:?}, generalized_ty={:?})",
233
235
a_ty, dir, b_vid,
@@ -236,6 +238,7 @@ impl<'a, 'tcx> CombineFields<'a, 'tcx> {
236
238
. borrow_mut ( )
237
239
. instantiate_and_push (
238
240
b_vid, generalized_ty, & mut stack) ;
241
+ obligations. extend ( new_obligations) ;
239
242
generalized_ty
240
243
}
241
244
} ;
@@ -247,15 +250,16 @@ impl<'a, 'tcx> CombineFields<'a, 'tcx> {
247
250
// relations wind up attributed to the same spans. We need
248
251
// to associate causes/spans with each of the relations in
249
252
// the stack to get this right.
250
- try!( match dir {
253
+ let RelateOk { obligations : new_obligations , .. } = try!( match dir {
251
254
BiTo => self . bivariate ( ) . relate ( & a_ty, & b_ty) ,
252
255
EqTo => self . equate ( ) . relate ( & a_ty, & b_ty) ,
253
256
SubtypeOf => self . sub ( ) . relate ( & a_ty, & b_ty) ,
254
257
SupertypeOf => self . sub ( ) . relate_with_variance ( ty:: Contravariant , & a_ty, & b_ty) ,
255
258
} ) ;
259
+ obligations. extend ( new_obligations) ;
256
260
}
257
261
258
- Ok ( ( ) )
262
+ Ok ( RelateOk { value : ( ) , obligations : obligations } )
259
263
}
260
264
261
265
/// 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> {
279
283
if generalize. cycle_detected {
280
284
Err ( TypeError :: CyclicTy )
281
285
} else {
282
- Ok ( u )
286
+ Ok ( RelateOk :: from ( u ) )
283
287
}
284
288
}
285
289
}
@@ -370,7 +374,7 @@ impl<'tcx, T:Clone + PartialEq> RelateResultCompare<'tcx, T> for RelateResult<'t
370
374
F : FnOnce ( ) -> TypeError < ' tcx > ,
371
375
{
372
376
self . clone ( ) . and_then ( |s| {
373
- if s == t {
377
+ if s. value == t {
374
378
self . clone ( )
375
379
} else {
376
380
Err ( f ( ) )
0 commit comments