@@ -38,7 +38,7 @@ use super::glb::Glb;
38
38
use super :: lub:: Lub ;
39
39
use super :: sub:: Sub ;
40
40
use super :: unify:: InferCtxtMethodsForSimplyUnifiableTypes ;
41
- use super :: { InferCtxt , cres } ;
41
+ use super :: { InferCtxt , CombineResult } ;
42
42
use super :: { MiscVariable , TypeTrace } ;
43
43
use super :: type_variable:: { RelationDir , BiTo , EqTo , SubtypeOf , SupertypeOf } ;
44
44
@@ -74,7 +74,7 @@ pub trait Combine<'tcx> : Sized {
74
74
fn lub < ' a > ( & ' a self ) -> Lub < ' a , ' tcx > { Lub ( self . fields ( ) . clone ( ) ) }
75
75
fn glb < ' a > ( & ' a self ) -> Glb < ' a , ' tcx > { Glb ( self . fields ( ) . clone ( ) ) }
76
76
77
- fn mts ( & self , a : & ty:: mt < ' tcx > , b : & ty:: mt < ' tcx > ) -> cres < ' tcx , ty:: mt < ' tcx > > {
77
+ fn mts ( & self , a : & ty:: mt < ' tcx > , b : & ty:: mt < ' tcx > ) -> CombineResult < ' tcx , ty:: mt < ' tcx > > {
78
78
debug ! ( "{}.mts({}, {})" ,
79
79
self . tag( ) ,
80
80
a. repr( self . tcx( ) ) ,
@@ -94,20 +94,20 @@ pub trait Combine<'tcx> : Sized {
94
94
}
95
95
96
96
fn tys_with_variance ( & self , variance : ty:: Variance , a : Ty < ' tcx > , b : Ty < ' tcx > )
97
- -> cres < ' tcx , Ty < ' tcx > > ;
97
+ -> CombineResult < ' tcx , Ty < ' tcx > > ;
98
98
99
- fn tys ( & self , a : Ty < ' tcx > , b : Ty < ' tcx > ) -> cres < ' tcx , Ty < ' tcx > > ;
99
+ fn tys ( & self , a : Ty < ' tcx > , b : Ty < ' tcx > ) -> CombineResult < ' tcx , Ty < ' tcx > > ;
100
100
101
101
fn regions_with_variance ( & self , variance : ty:: Variance , a : ty:: Region , b : ty:: Region )
102
- -> cres < ' tcx , ty:: Region > ;
102
+ -> CombineResult < ' tcx , ty:: Region > ;
103
103
104
- fn regions ( & self , a : ty:: Region , b : ty:: Region ) -> cres < ' tcx , ty:: Region > ;
104
+ fn regions ( & self , a : ty:: Region , b : ty:: Region ) -> CombineResult < ' tcx , ty:: Region > ;
105
105
106
106
fn substs ( & self ,
107
107
item_def_id : ast:: DefId ,
108
108
a_subst : & subst:: Substs < ' tcx > ,
109
109
b_subst : & subst:: Substs < ' tcx > )
110
- -> cres < ' tcx , subst:: Substs < ' tcx > >
110
+ -> CombineResult < ' tcx , subst:: Substs < ' tcx > >
111
111
{
112
112
debug ! ( "substs: item_def_id={} a_subst={} b_subst={}" ,
113
113
item_def_id. repr( self . infcx( ) . tcx) ,
@@ -126,7 +126,7 @@ pub trait Combine<'tcx> : Sized {
126
126
variances : Option < & ty:: ItemVariances > ,
127
127
a_subst : & subst:: Substs < ' tcx > ,
128
128
b_subst : & subst:: Substs < ' tcx > )
129
- -> cres < ' tcx , subst:: Substs < ' tcx > >
129
+ -> CombineResult < ' tcx , subst:: Substs < ' tcx > >
130
130
{
131
131
let mut substs = subst:: Substs :: empty ( ) ;
132
132
@@ -163,7 +163,7 @@ pub trait Combine<'tcx> : Sized {
163
163
variances : Option < & [ ty:: Variance ] > ,
164
164
a_tys : & [ Ty < ' tcx > ] ,
165
165
b_tys : & [ Ty < ' tcx > ] )
166
- -> cres < ' tcx , Vec < Ty < ' tcx > > >
166
+ -> CombineResult < ' tcx , Vec < Ty < ' tcx > > >
167
167
{
168
168
if a_tys. len ( ) != b_tys. len ( ) {
169
169
return Err ( ty:: terr_ty_param_size ( expected_found ( this,
@@ -183,7 +183,7 @@ pub trait Combine<'tcx> : Sized {
183
183
variances : Option < & [ ty:: Variance ] > ,
184
184
a_rs : & [ ty:: Region ] ,
185
185
b_rs : & [ ty:: Region ] )
186
- -> cres < ' tcx , Vec < ty:: Region > >
186
+ -> CombineResult < ' tcx , Vec < ty:: Region > >
187
187
{
188
188
let tcx = this. infcx ( ) . tcx ;
189
189
let num_region_params = a_rs. len ( ) ;
@@ -212,7 +212,7 @@ pub trait Combine<'tcx> : Sized {
212
212
}
213
213
214
214
fn bare_fn_tys ( & self , a : & ty:: BareFnTy < ' tcx > ,
215
- b : & ty:: BareFnTy < ' tcx > ) -> cres < ' tcx , ty:: BareFnTy < ' tcx > > {
215
+ b : & ty:: BareFnTy < ' tcx > ) -> CombineResult < ' tcx , ty:: BareFnTy < ' tcx > > {
216
216
let unsafety = try!( self . unsafeties ( a. unsafety , b. unsafety ) ) ;
217
217
let abi = try!( self . abi ( a. abi , b. abi ) ) ;
218
218
let sig = try!( self . binders ( & a. sig , & b. sig ) ) ;
@@ -221,7 +221,7 @@ pub trait Combine<'tcx> : Sized {
221
221
sig : sig} )
222
222
}
223
223
224
- fn fn_sigs ( & self , a : & ty:: FnSig < ' tcx > , b : & ty:: FnSig < ' tcx > ) -> cres < ' tcx , ty:: FnSig < ' tcx > > {
224
+ fn fn_sigs ( & self , a : & ty:: FnSig < ' tcx > , b : & ty:: FnSig < ' tcx > ) -> CombineResult < ' tcx , ty:: FnSig < ' tcx > > {
225
225
if a. variadic != b. variadic {
226
226
return Err ( ty:: terr_variadic_mismatch ( expected_found ( self , a. variadic , b. variadic ) ) ) ;
227
227
}
@@ -248,7 +248,7 @@ pub trait Combine<'tcx> : Sized {
248
248
fn argvecs < ' tcx , C > ( combiner : & C ,
249
249
a_args : & [ Ty < ' tcx > ] ,
250
250
b_args : & [ Ty < ' tcx > ] )
251
- -> cres < ' tcx , Vec < Ty < ' tcx > > >
251
+ -> CombineResult < ' tcx , Vec < Ty < ' tcx > > >
252
252
where C : Combine < ' tcx > {
253
253
if a_args. len ( ) == b_args. len ( ) {
254
254
a_args. iter ( ) . zip ( b_args. iter ( ) )
@@ -259,19 +259,19 @@ pub trait Combine<'tcx> : Sized {
259
259
}
260
260
}
261
261
262
- fn args ( & self , a : Ty < ' tcx > , b : Ty < ' tcx > ) -> cres < ' tcx , Ty < ' tcx > > {
262
+ fn args ( & self , a : Ty < ' tcx > , b : Ty < ' tcx > ) -> CombineResult < ' tcx , Ty < ' tcx > > {
263
263
self . tys_with_variance ( ty:: Contravariant , a, b) . and_then ( |t| Ok ( t) )
264
264
}
265
265
266
- fn unsafeties ( & self , a : Unsafety , b : Unsafety ) -> cres < ' tcx , Unsafety > {
266
+ fn unsafeties ( & self , a : Unsafety , b : Unsafety ) -> CombineResult < ' tcx , Unsafety > {
267
267
if a != b {
268
268
Err ( ty:: terr_unsafety_mismatch ( expected_found ( self , a, b) ) )
269
269
} else {
270
270
Ok ( a)
271
271
}
272
272
}
273
273
274
- fn abi ( & self , a : abi:: Abi , b : abi:: Abi ) -> cres < ' tcx , abi:: Abi > {
274
+ fn abi ( & self , a : abi:: Abi , b : abi:: Abi ) -> CombineResult < ' tcx , abi:: Abi > {
275
275
if a == b {
276
276
Ok ( a)
277
277
} else {
@@ -282,7 +282,7 @@ pub trait Combine<'tcx> : Sized {
282
282
fn projection_tys ( & self ,
283
283
a : & ty:: ProjectionTy < ' tcx > ,
284
284
b : & ty:: ProjectionTy < ' tcx > )
285
- -> cres < ' tcx , ty:: ProjectionTy < ' tcx > >
285
+ -> CombineResult < ' tcx , ty:: ProjectionTy < ' tcx > >
286
286
{
287
287
if a. item_name != b. item_name {
288
288
Err ( ty:: terr_projection_name_mismatched (
@@ -296,7 +296,7 @@ pub trait Combine<'tcx> : Sized {
296
296
fn projection_predicates ( & self ,
297
297
a : & ty:: ProjectionPredicate < ' tcx > ,
298
298
b : & ty:: ProjectionPredicate < ' tcx > )
299
- -> cres < ' tcx , ty:: ProjectionPredicate < ' tcx > >
299
+ -> CombineResult < ' tcx , ty:: ProjectionPredicate < ' tcx > >
300
300
{
301
301
let projection_ty = try!( self . projection_tys ( & a. projection_ty , & b. projection_ty ) ) ;
302
302
let ty = try!( self . tys ( a. ty , b. ty ) ) ;
@@ -306,7 +306,7 @@ pub trait Combine<'tcx> : Sized {
306
306
fn projection_bounds ( & self ,
307
307
a : & Vec < ty:: PolyProjectionPredicate < ' tcx > > ,
308
308
b : & Vec < ty:: PolyProjectionPredicate < ' tcx > > )
309
- -> cres < ' tcx , Vec < ty:: PolyProjectionPredicate < ' tcx > > >
309
+ -> CombineResult < ' tcx , Vec < ty:: PolyProjectionPredicate < ' tcx > > >
310
310
{
311
311
// To be compatible, `a` and `b` must be for precisely the
312
312
// same set of traits and item names. We always require that
@@ -326,7 +326,7 @@ pub trait Combine<'tcx> : Sized {
326
326
fn existential_bounds ( & self ,
327
327
a : & ty:: ExistentialBounds < ' tcx > ,
328
328
b : & ty:: ExistentialBounds < ' tcx > )
329
- -> cres < ' tcx , ty:: ExistentialBounds < ' tcx > >
329
+ -> CombineResult < ' tcx , ty:: ExistentialBounds < ' tcx > >
330
330
{
331
331
let r = try!( self . regions_with_variance ( ty:: Contravariant , a. region_bound , b. region_bound ) ) ;
332
332
let nb = try!( self . builtin_bounds ( a. builtin_bounds , b. builtin_bounds ) ) ;
@@ -339,7 +339,7 @@ pub trait Combine<'tcx> : Sized {
339
339
fn builtin_bounds ( & self ,
340
340
a : BuiltinBounds ,
341
341
b : BuiltinBounds )
342
- -> cres < ' tcx , BuiltinBounds >
342
+ -> CombineResult < ' tcx , BuiltinBounds >
343
343
{
344
344
// Two sets of builtin bounds are only relatable if they are
345
345
// precisely the same (but see the coercion code).
@@ -353,7 +353,7 @@ pub trait Combine<'tcx> : Sized {
353
353
fn trait_refs ( & self ,
354
354
a : & ty:: TraitRef < ' tcx > ,
355
355
b : & ty:: TraitRef < ' tcx > )
356
- -> cres < ' tcx , ty:: TraitRef < ' tcx > >
356
+ -> CombineResult < ' tcx , ty:: TraitRef < ' tcx > >
357
357
{
358
358
// Different traits cannot be related
359
359
if a. def_id != b. def_id {
@@ -364,14 +364,14 @@ pub trait Combine<'tcx> : Sized {
364
364
}
365
365
}
366
366
367
- fn binders < T > ( & self , a : & ty:: Binder < T > , b : & ty:: Binder < T > ) -> cres < ' tcx , ty:: Binder < T > >
367
+ fn binders < T > ( & self , a : & ty:: Binder < T > , b : & ty:: Binder < T > ) -> CombineResult < ' tcx , ty:: Binder < T > >
368
368
where T : Combineable < ' tcx > ;
369
369
// this must be overridden to do correctly, so as to account for higher-ranked
370
370
// behavior
371
371
}
372
372
373
373
pub trait Combineable < ' tcx > : Repr < ' tcx > + TypeFoldable < ' tcx > {
374
- fn combine < C : Combine < ' tcx > > ( combiner : & C , a : & Self , b : & Self ) -> cres < ' tcx , Self > ;
374
+ fn combine < C : Combine < ' tcx > > ( combiner : & C , a : & Self , b : & Self ) -> CombineResult < ' tcx , Self > ;
375
375
}
376
376
377
377
impl < ' tcx , T > Combineable < ' tcx > for Rc < T >
@@ -380,7 +380,7 @@ impl<'tcx,T> Combineable<'tcx> for Rc<T>
380
380
fn combine < C > ( combiner : & C ,
381
381
a : & Rc < T > ,
382
382
b : & Rc < T > )
383
- -> cres < ' tcx , Rc < T > >
383
+ -> CombineResult < ' tcx , Rc < T > >
384
384
where C : Combine < ' tcx > {
385
385
Ok ( Rc :: new ( try!( Combineable :: combine ( combiner, & * * a, & * * b) ) ) )
386
386
}
@@ -390,7 +390,7 @@ impl<'tcx> Combineable<'tcx> for ty::TraitRef<'tcx> {
390
390
fn combine < C > ( combiner : & C ,
391
391
a : & ty:: TraitRef < ' tcx > ,
392
392
b : & ty:: TraitRef < ' tcx > )
393
- -> cres < ' tcx , ty:: TraitRef < ' tcx > >
393
+ -> CombineResult < ' tcx , ty:: TraitRef < ' tcx > >
394
394
where C : Combine < ' tcx > {
395
395
combiner. trait_refs ( a, b)
396
396
}
@@ -400,7 +400,7 @@ impl<'tcx> Combineable<'tcx> for Ty<'tcx> {
400
400
fn combine < C > ( combiner : & C ,
401
401
a : & Ty < ' tcx > ,
402
402
b : & Ty < ' tcx > )
403
- -> cres < ' tcx , Ty < ' tcx > >
403
+ -> CombineResult < ' tcx , Ty < ' tcx > >
404
404
where C : Combine < ' tcx > {
405
405
combiner. tys ( * a, * b)
406
406
}
@@ -410,7 +410,7 @@ impl<'tcx> Combineable<'tcx> for ty::ProjectionPredicate<'tcx> {
410
410
fn combine < C > ( combiner : & C ,
411
411
a : & ty:: ProjectionPredicate < ' tcx > ,
412
412
b : & ty:: ProjectionPredicate < ' tcx > )
413
- -> cres < ' tcx , ty:: ProjectionPredicate < ' tcx > >
413
+ -> CombineResult < ' tcx , ty:: ProjectionPredicate < ' tcx > >
414
414
where C : Combine < ' tcx > {
415
415
combiner. projection_predicates ( a, b)
416
416
}
@@ -420,7 +420,7 @@ impl<'tcx> Combineable<'tcx> for ty::FnSig<'tcx> {
420
420
fn combine < C > ( combiner : & C ,
421
421
a : & ty:: FnSig < ' tcx > ,
422
422
b : & ty:: FnSig < ' tcx > )
423
- -> cres < ' tcx , ty:: FnSig < ' tcx > >
423
+ -> CombineResult < ' tcx , ty:: FnSig < ' tcx > >
424
424
where C : Combine < ' tcx > {
425
425
combiner. fn_sigs ( a, b)
426
426
}
@@ -448,7 +448,7 @@ pub fn expected_found<'tcx, C, T>(this: &C,
448
448
pub fn super_tys < ' tcx , C > ( this : & C ,
449
449
a : Ty < ' tcx > ,
450
450
b : Ty < ' tcx > )
451
- -> cres < ' tcx , Ty < ' tcx > >
451
+ -> CombineResult < ' tcx , Ty < ' tcx > >
452
452
where C : Combine < ' tcx > {
453
453
let tcx = this. infcx ( ) . tcx ;
454
454
let a_sty = & a. sty ;
@@ -616,7 +616,7 @@ pub fn super_tys<'tcx, C>(this: &C,
616
616
vid_is_expected : bool ,
617
617
vid : ty:: IntVid ,
618
618
val : ty:: IntVarValue )
619
- -> cres < ' tcx , Ty < ' tcx > >
619
+ -> CombineResult < ' tcx , Ty < ' tcx > >
620
620
where C : Combine < ' tcx > {
621
621
try!( this. infcx ( ) . simple_var_t ( vid_is_expected, vid, val) ) ;
622
622
match val {
@@ -629,7 +629,7 @@ pub fn super_tys<'tcx, C>(this: &C,
629
629
vid_is_expected : bool ,
630
630
vid : ty:: FloatVid ,
631
631
val : ast:: FloatTy )
632
- -> cres < ' tcx , Ty < ' tcx > >
632
+ -> CombineResult < ' tcx , Ty < ' tcx > >
633
633
where C : Combine < ' tcx > {
634
634
try!( this. infcx ( ) . simple_var_t ( vid_is_expected, vid, val) ) ;
635
635
Ok ( ty:: mk_mach_float ( this. tcx ( ) , val) )
@@ -660,7 +660,7 @@ impl<'f, 'tcx> CombineFields<'f, 'tcx> {
660
660
a_ty : Ty < ' tcx > ,
661
661
dir : RelationDir ,
662
662
b_vid : ty:: TyVid )
663
- -> cres < ' tcx , ( ) >
663
+ -> CombineResult < ' tcx , ( ) >
664
664
{
665
665
let tcx = self . infcx . tcx ;
666
666
let mut stack = Vec :: new ( ) ;
@@ -746,7 +746,7 @@ impl<'f, 'tcx> CombineFields<'f, 'tcx> {
746
746
ty : Ty < ' tcx > ,
747
747
for_vid : ty:: TyVid ,
748
748
make_region_vars : bool )
749
- -> cres < ' tcx , Ty < ' tcx > >
749
+ -> CombineResult < ' tcx , Ty < ' tcx > >
750
750
{
751
751
let mut generalize = Generalizer {
752
752
infcx : self . infcx ,
@@ -839,3 +839,23 @@ impl<'cx, 'tcx> ty_fold::TypeFolder<'tcx> for Generalizer<'cx, 'tcx> {
839
839
self . infcx . next_region_var ( MiscVariable ( self . span ) )
840
840
}
841
841
}
842
+
843
+ pub trait CombineResultCompare < ' tcx , T > {
844
+ fn compare < F > ( & self , t : T , f : F ) -> CombineResult < ' tcx , T > where
845
+ F : FnOnce ( ) -> ty:: type_err < ' tcx > ;
846
+ }
847
+
848
+ impl < ' tcx , T : Clone + PartialEq > CombineResultCompare < ' tcx , T > for CombineResult < ' tcx , T > {
849
+ fn compare < F > ( & self , t : T , f : F ) -> CombineResult < ' tcx , T > where
850
+ F : FnOnce ( ) -> ty:: type_err < ' tcx > ,
851
+ {
852
+ ( * self ) . clone ( ) . and_then ( |s| {
853
+ if s == t {
854
+ ( * self ) . clone ( )
855
+ } else {
856
+ Err ( f ( ) )
857
+ }
858
+ } )
859
+ }
860
+ }
861
+
0 commit comments