@@ -27,13 +27,13 @@ use middle::region::CodeExtent;
27
27
use ty:: subst;
28
28
use ty:: subst:: Substs ;
29
29
use ty:: subst:: Subst ;
30
- use traits:: { self , ProjectionMode } ;
31
30
use ty:: adjustment;
32
31
use ty:: { TyVid , IntVid , FloatVid } ;
33
32
use ty:: { self , Ty , TyCtxt } ;
34
33
use ty:: error:: { ExpectedFound , TypeError , UnconstrainedNumeric } ;
35
34
use ty:: fold:: { TypeFolder , TypeFoldable } ;
36
35
use ty:: relate:: { Relate , RelateResult , TypeRelation } ;
36
+ use traits:: { self , PredicateObligations , ProjectionMode } ;
37
37
use rustc_data_structures:: unify:: { self , UnificationTable } ;
38
38
use std:: cell:: { RefCell , Ref } ;
39
39
use std:: fmt;
@@ -63,6 +63,12 @@ pub mod sub;
63
63
pub mod type_variable;
64
64
pub mod unify_key;
65
65
66
+ pub struct InferOk < ' tcx , T > {
67
+ pub value : T ,
68
+ pub obligations : PredicateObligations < ' tcx > ,
69
+ }
70
+ pub type InferResult < ' tcx , T > = Result < InferOk < ' tcx , T > , TypeError < ' tcx > > ;
71
+
66
72
pub type Bound < T > = Option < T > ;
67
73
pub type UnitResult < ' tcx > = RelateResult < ' tcx , ( ) > ; // "unify result"
68
74
pub type FixupResult < T > = Result < T , FixupError > ; // "fixup result"
@@ -391,16 +397,15 @@ pub fn mk_subty<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>,
391
397
origin : TypeOrigin ,
392
398
a : Ty < ' tcx > ,
393
399
b : Ty < ' tcx > )
394
- -> UnitResult < ' tcx >
400
+ -> InferResult < ' tcx , ( ) >
395
401
{
396
402
debug ! ( "mk_subty({:?} <: {:?})" , a, b) ;
397
403
cx. sub_types ( a_is_expected, origin, a, b)
398
404
}
399
405
400
- pub fn can_mk_subty < ' a , ' tcx > ( cx : & InferCtxt < ' a , ' tcx > ,
401
- a : Ty < ' tcx > ,
402
- b : Ty < ' tcx > )
403
- -> UnitResult < ' tcx > {
406
+ pub fn can_mk_subty < ' a , ' tcx > ( cx : & InferCtxt < ' a , ' tcx > , a : Ty < ' tcx > , b : Ty < ' tcx > )
407
+ -> UnitResult < ' tcx >
408
+ {
404
409
debug ! ( "can_mk_subty({:?} <: {:?})" , a, b) ;
405
410
cx. probe ( |_| {
406
411
let trace = TypeTrace {
@@ -412,7 +417,7 @@ pub fn can_mk_subty<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>,
412
417
}
413
418
414
419
pub fn can_mk_eqty < ' a , ' tcx > ( cx : & InferCtxt < ' a , ' tcx > , a : Ty < ' tcx > , b : Ty < ' tcx > )
415
- -> UnitResult < ' tcx >
420
+ -> UnitResult < ' tcx >
416
421
{
417
422
cx. can_equate ( & a, & b)
418
423
}
@@ -432,7 +437,7 @@ pub fn mk_eqty<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>,
432
437
origin : TypeOrigin ,
433
438
a : Ty < ' tcx > ,
434
439
b : Ty < ' tcx > )
435
- -> UnitResult < ' tcx >
440
+ -> InferResult < ' tcx , ( ) >
436
441
{
437
442
debug ! ( "mk_eqty({:?} <: {:?})" , a, b) ;
438
443
cx. eq_types ( a_is_expected, origin, a, b)
@@ -443,7 +448,7 @@ pub fn mk_eq_trait_refs<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>,
443
448
origin : TypeOrigin ,
444
449
a : ty:: TraitRef < ' tcx > ,
445
450
b : ty:: TraitRef < ' tcx > )
446
- -> UnitResult < ' tcx >
451
+ -> InferResult < ' tcx , ( ) >
447
452
{
448
453
debug ! ( "mk_eq_trait_refs({:?} = {:?})" , a, b) ;
449
454
cx. eq_trait_refs ( a_is_expected, origin, a, b)
@@ -454,7 +459,7 @@ pub fn mk_sub_poly_trait_refs<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>,
454
459
origin : TypeOrigin ,
455
460
a : ty:: PolyTraitRef < ' tcx > ,
456
461
b : ty:: PolyTraitRef < ' tcx > )
457
- -> UnitResult < ' tcx >
462
+ -> InferResult < ' tcx , ( ) >
458
463
{
459
464
debug ! ( "mk_sub_poly_trait_refs({:?} <: {:?})" , a, b) ;
460
465
cx. sub_poly_trait_refs ( a_is_expected, origin, a, b)
@@ -465,7 +470,7 @@ pub fn mk_eq_impl_headers<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>,
465
470
origin : TypeOrigin ,
466
471
a : & ty:: ImplHeader < ' tcx > ,
467
472
b : & ty:: ImplHeader < ' tcx > )
468
- -> UnitResult < ' tcx >
473
+ -> InferResult < ' tcx , ( ) >
469
474
{
470
475
debug ! ( "mk_eq_impl_header({:?} = {:?})" , a, b) ;
471
476
match ( a. trait_ref , b. trait_ref ) {
@@ -574,6 +579,12 @@ pub fn drain_fulfillment_cx<'a,'tcx,T>(infcx: &InferCtxt<'a,'tcx>,
574
579
Ok ( infcx. tcx . erase_regions ( & result) )
575
580
}
576
581
582
+ impl < ' tcx , T > InferOk < ' tcx , T > {
583
+ fn unit ( self ) -> InferOk < ' tcx , ( ) > {
584
+ InferOk { value : ( ) , obligations : self . obligations }
585
+ }
586
+ }
587
+
577
588
impl < ' a , ' tcx > InferCtxt < ' a , ' tcx > {
578
589
pub fn projection_mode ( & self ) -> ProjectionMode {
579
590
self . projection_mode
@@ -661,39 +672,51 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
661
672
}
662
673
663
674
fn combine_fields ( & ' a self , a_is_expected : bool , trace : TypeTrace < ' tcx > )
664
- -> CombineFields < ' a , ' tcx > {
665
- CombineFields { infcx : self ,
666
- a_is_expected : a_is_expected,
667
- trace : trace,
668
- cause : None }
675
+ -> CombineFields < ' a , ' tcx >
676
+ {
677
+ CombineFields {
678
+ infcx : self ,
679
+ a_is_expected : a_is_expected,
680
+ trace : trace,
681
+ cause : None ,
682
+ obligations : PredicateObligations :: new ( ) ,
683
+ }
669
684
}
670
685
671
686
pub fn equate < T > ( & ' a self , a_is_expected : bool , trace : TypeTrace < ' tcx > , a : & T , b : & T )
672
- -> RelateResult < ' tcx , T >
687
+ -> InferResult < ' tcx , T >
673
688
where T : Relate < ' a , ' tcx >
674
689
{
675
- self . combine_fields ( a_is_expected, trace) . equate ( ) . relate ( a, b)
690
+ let mut equate = self . combine_fields ( a_is_expected, trace) . equate ( ) ;
691
+ let result = equate. relate ( a, b) ;
692
+ result. map ( |t| InferOk { value : t, obligations : equate. obligations ( ) } )
676
693
}
677
694
678
695
pub fn sub < T > ( & ' a self , a_is_expected : bool , trace : TypeTrace < ' tcx > , a : & T , b : & T )
679
- -> RelateResult < ' tcx , T >
696
+ -> InferResult < ' tcx , T >
680
697
where T : Relate < ' a , ' tcx >
681
698
{
682
- self . combine_fields ( a_is_expected, trace) . sub ( ) . relate ( a, b)
699
+ let mut sub = self . combine_fields ( a_is_expected, trace) . sub ( ) ;
700
+ let result = sub. relate ( a, b) ;
701
+ result. map ( |t| InferOk { value : t, obligations : sub. obligations ( ) } )
683
702
}
684
703
685
704
pub fn lub < T > ( & ' a self , a_is_expected : bool , trace : TypeTrace < ' tcx > , a : & T , b : & T )
686
- -> RelateResult < ' tcx , T >
705
+ -> InferResult < ' tcx , T >
687
706
where T : Relate < ' a , ' tcx >
688
707
{
689
- self . combine_fields ( a_is_expected, trace) . lub ( ) . relate ( a, b)
708
+ let mut lub = self . combine_fields ( a_is_expected, trace) . lub ( ) ;
709
+ let result = lub. relate ( a, b) ;
710
+ result. map ( |t| InferOk { value : t, obligations : lub. obligations ( ) } )
690
711
}
691
712
692
713
pub fn glb < T > ( & ' a self , a_is_expected : bool , trace : TypeTrace < ' tcx > , a : & T , b : & T )
693
- -> RelateResult < ' tcx , T >
714
+ -> InferResult < ' tcx , T >
694
715
where T : Relate < ' a , ' tcx >
695
716
{
696
- self . combine_fields ( a_is_expected, trace) . glb ( ) . relate ( a, b)
717
+ let mut glb = self . combine_fields ( a_is_expected, trace) . glb ( ) ;
718
+ let result = glb. relate ( a, b) ;
719
+ result. map ( |t| InferOk { value : t, obligations : glb. obligations ( ) } )
697
720
}
698
721
699
722
fn start_snapshot ( & self ) -> CombinedSnapshot {
@@ -829,12 +852,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
829
852
origin : TypeOrigin ,
830
853
a : Ty < ' tcx > ,
831
854
b : Ty < ' tcx > )
832
- -> UnitResult < ' tcx >
855
+ -> InferResult < ' tcx , ( ) >
833
856
{
834
857
debug ! ( "sub_types({:?} <: {:?})" , a, b) ;
835
858
self . commit_if_ok ( |_| {
836
859
let trace = TypeTrace :: types ( origin, a_is_expected, a, b) ;
837
- self . sub ( a_is_expected, trace, & a, & b) . map ( |_| ( ) )
860
+ self . sub ( a_is_expected, trace, & a, & b) . map ( |ok| ok . unit ( ) )
838
861
} )
839
862
}
840
863
@@ -843,11 +866,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
843
866
origin : TypeOrigin ,
844
867
a : Ty < ' tcx > ,
845
868
b : Ty < ' tcx > )
846
- -> UnitResult < ' tcx >
869
+ -> InferResult < ' tcx , ( ) >
847
870
{
848
871
self . commit_if_ok ( |_| {
849
872
let trace = TypeTrace :: types ( origin, a_is_expected, a, b) ;
850
- self . equate ( a_is_expected, trace, & a, & b) . map ( |_| ( ) )
873
+ self . equate ( a_is_expected, trace, & a, & b) . map ( |ok| ok . unit ( ) )
851
874
} )
852
875
}
853
876
@@ -856,7 +879,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
856
879
origin : TypeOrigin ,
857
880
a : ty:: TraitRef < ' tcx > ,
858
881
b : ty:: TraitRef < ' tcx > )
859
- -> UnitResult < ' tcx >
882
+ -> InferResult < ' tcx , ( ) >
860
883
{
861
884
debug ! ( "eq_trait_refs({:?} <: {:?})" ,
862
885
a,
@@ -866,7 +889,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
866
889
origin : origin,
867
890
values : TraitRefs ( expected_found ( a_is_expected, a. clone ( ) , b. clone ( ) ) )
868
891
} ;
869
- self . equate ( a_is_expected, trace, & a, & b) . map ( |_| ( ) )
892
+ self . equate ( a_is_expected, trace, & a, & b) . map ( |ok| ok . unit ( ) )
870
893
} )
871
894
}
872
895
@@ -875,7 +898,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
875
898
origin : TypeOrigin ,
876
899
a : ty:: PolyTraitRef < ' tcx > ,
877
900
b : ty:: PolyTraitRef < ' tcx > )
878
- -> UnitResult < ' tcx >
901
+ -> InferResult < ' tcx , ( ) >
879
902
{
880
903
debug ! ( "sub_poly_trait_refs({:?} <: {:?})" ,
881
904
a,
@@ -885,7 +908,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
885
908
origin : origin,
886
909
values : PolyTraitRefs ( expected_found ( a_is_expected, a. clone ( ) , b. clone ( ) ) )
887
910
} ;
888
- self . sub ( a_is_expected, trace, & a, & b) . map ( |_| ( ) )
911
+ self . sub ( a_is_expected, trace, & a, & b) . map ( |ok| ok . unit ( ) )
889
912
} )
890
913
}
891
914
@@ -928,20 +951,22 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
928
951
pub fn equality_predicate ( & self ,
929
952
span : Span ,
930
953
predicate : & ty:: PolyEquatePredicate < ' tcx > )
931
- -> UnitResult < ' tcx > {
954
+ -> InferResult < ' tcx , ( ) >
955
+ {
932
956
self . commit_if_ok ( |snapshot| {
933
957
let ( ty:: EquatePredicate ( a, b) , skol_map) =
934
958
self . skolemize_late_bound_regions ( predicate, snapshot) ;
935
959
let origin = TypeOrigin :: EquatePredicate ( span) ;
936
- let ( ) = mk_eqty ( self , false , origin, a, b) ?;
937
- self . leak_check ( & skol_map, snapshot)
960
+ let eqty_ok = mk_eqty ( self , false , origin, a, b) ?;
961
+ self . leak_check ( & skol_map, snapshot) . map ( |_| eqty_ok . unit ( ) )
938
962
} )
939
963
}
940
964
941
965
pub fn region_outlives_predicate ( & self ,
942
966
span : Span ,
943
967
predicate : & ty:: PolyRegionOutlivesPredicate )
944
- -> UnitResult < ' tcx > {
968
+ -> UnitResult < ' tcx >
969
+ {
945
970
self . commit_if_ok ( |snapshot| {
946
971
let ( ty:: OutlivesPredicate ( r_a, r_b) , skol_map) =
947
972
self . skolemize_late_bound_regions ( predicate, snapshot) ;
0 commit comments