@@ -102,6 +102,7 @@ use middle::ty::{MethodCall, MethodCallee};
102
102
use middle:: ty:: adjustment;
103
103
use middle:: ty:: error:: TypeError ;
104
104
use middle:: ty:: fold:: { TypeFolder , TypeFoldable } ;
105
+ use middle:: ty:: relate:: RelateOk ;
105
106
use middle:: ty:: util:: Representability ;
106
107
use require_c_abi_if_variadic;
107
108
use rscope:: { ElisionFailureInfo , RegionScope } ;
@@ -1206,6 +1207,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1206
1207
& self . inh . infcx
1207
1208
}
1208
1209
1210
+ pub fn fulfillment_cx ( & self ) -> & RefCell < traits:: FulfillmentContext < ' tcx > > {
1211
+ & self . inh . fulfillment_cx
1212
+ }
1213
+
1209
1214
pub fn param_env ( & self ) -> & ty:: ParameterEnvironment < ' a , ' tcx > {
1210
1215
& self . inh . infcx . parameter_environment
1211
1216
}
@@ -1248,6 +1253,21 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1248
1253
ty
1249
1254
}
1250
1255
1256
+ pub fn common_supertype ( & self ,
1257
+ origin : TypeOrigin ,
1258
+ a_is_expected : bool ,
1259
+ a : Ty < ' tcx > ,
1260
+ b : Ty < ' tcx > )
1261
+ -> Ty < ' tcx >
1262
+ {
1263
+ let RelateOk { value, obligations } = infer:: common_supertype (
1264
+ self . infcx ( ) , origin, a_is_expected, a, b) ;
1265
+ for obligation in obligations {
1266
+ self . register_predicate ( obligation) ;
1267
+ }
1268
+ value
1269
+ }
1270
+
1251
1271
fn record_deferred_call_resolution ( & self ,
1252
1272
closure_def_id : DefId ,
1253
1273
r : DeferredCallResolutionHandler < ' tcx > ) {
@@ -1593,6 +1613,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1593
1613
sup : Ty < ' tcx > )
1594
1614
-> Result < ( ) , TypeError < ' tcx > > {
1595
1615
infer:: mk_subty ( self . infcx ( ) , a_is_expected, origin, sub, sup)
1616
+ . map ( |RelateOk { value, obligations } | {
1617
+ for obligation in obligations {
1618
+ self . register_predicate ( obligation) ;
1619
+ }
1620
+ value
1621
+ } )
1596
1622
}
1597
1623
1598
1624
pub fn mk_eqty ( & self ,
@@ -1602,6 +1628,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1602
1628
sup : Ty < ' tcx > )
1603
1629
-> Result < ( ) , TypeError < ' tcx > > {
1604
1630
infer:: mk_eqty ( self . infcx ( ) , a_is_expected, origin, sub, sup)
1631
+ . map ( |RelateOk { value, obligations } | {
1632
+ for obligation in obligations {
1633
+ self . register_predicate ( obligation) ;
1634
+ }
1635
+ value
1636
+ } )
1605
1637
}
1606
1638
1607
1639
pub fn mk_subr ( & self ,
@@ -1885,9 +1917,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1885
1917
Neither => {
1886
1918
if let Some ( default) = default_map. get ( ty) {
1887
1919
let default = default. clone ( ) ;
1888
- match infer :: mk_eqty ( self . infcx ( ) , false ,
1889
- TypeOrigin :: Misc ( default. origin_span ) ,
1890
- ty, default. ty ) {
1920
+ match self . mk_eqty ( false ,
1921
+ TypeOrigin :: Misc ( default. origin_span ) ,
1922
+ ty, default. ty ) {
1891
1923
Ok ( ( ) ) => { }
1892
1924
Err ( _) => {
1893
1925
conflicts. push ( ( * ty, default) ) ;
@@ -1978,9 +2010,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1978
2010
Neither => {
1979
2011
if let Some ( default) = default_map. get ( ty) {
1980
2012
let default = default. clone ( ) ;
1981
- match infer :: mk_eqty ( self . infcx ( ) , false ,
1982
- TypeOrigin :: Misc ( default. origin_span ) ,
1983
- ty, default. ty ) {
2013
+ match self . mk_eqty ( false ,
2014
+ TypeOrigin :: Misc ( default. origin_span ) ,
2015
+ ty, default. ty ) {
1984
2016
Ok ( ( ) ) => { }
1985
2017
Err ( _) => {
1986
2018
result = Some ( default) ;
@@ -2880,18 +2912,16 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
2880
2912
Some ( ref else_expr) => {
2881
2913
check_expr_with_expectation ( fcx, & else_expr, expected) ;
2882
2914
let else_ty = fcx. expr_ty ( & else_expr) ;
2883
- infer:: common_supertype ( fcx. infcx ( ) ,
2884
- TypeOrigin :: IfExpression ( sp) ,
2885
- true ,
2886
- then_ty,
2887
- else_ty)
2915
+ fcx. common_supertype ( TypeOrigin :: IfExpression ( sp) ,
2916
+ true ,
2917
+ then_ty,
2918
+ else_ty)
2888
2919
}
2889
2920
None => {
2890
- infer:: common_supertype ( fcx. infcx ( ) ,
2891
- TypeOrigin :: IfExpressionWithNoElse ( sp) ,
2892
- false ,
2893
- then_ty,
2894
- fcx. tcx ( ) . mk_nil ( ) )
2921
+ fcx. common_supertype ( TypeOrigin :: IfExpressionWithNoElse ( sp) ,
2922
+ false ,
2923
+ then_ty,
2924
+ fcx. tcx ( ) . mk_nil ( ) )
2895
2925
}
2896
2926
} ;
2897
2927
@@ -3685,11 +3715,10 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
3685
3715
Some ( fcx. tcx ( ) . types . err )
3686
3716
}
3687
3717
( Some ( t_start) , Some ( t_end) ) => {
3688
- Some ( infer:: common_supertype ( fcx. infcx ( ) ,
3689
- TypeOrigin :: RangeExpression ( expr. span ) ,
3690
- true ,
3691
- t_start,
3692
- t_end) )
3718
+ Some ( fcx. common_supertype ( TypeOrigin :: RangeExpression ( expr. span ) ,
3719
+ true ,
3720
+ t_start,
3721
+ t_end) )
3693
3722
}
3694
3723
_ => None
3695
3724
} ;
0 commit comments