@@ -102,6 +102,7 @@ use middle::ty::{MethodCall, MethodCallee};
102102use middle:: ty:: adjustment;
103103use middle:: ty:: error:: TypeError ;
104104use middle:: ty:: fold:: { TypeFolder , TypeFoldable } ;
105+ use middle:: ty:: relate:: RelateOk ;
105106use middle:: ty:: util:: Representability ;
106107use require_c_abi_if_variadic;
107108use rscope:: { ElisionFailureInfo , RegionScope } ;
@@ -1206,6 +1207,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12061207 & self . inh . infcx
12071208 }
12081209
1210+ pub fn fulfillment_cx ( & self ) -> & RefCell < traits:: FulfillmentContext < ' tcx > > {
1211+ & self . inh . fulfillment_cx
1212+ }
1213+
12091214 pub fn param_env ( & self ) -> & ty:: ParameterEnvironment < ' a , ' tcx > {
12101215 & self . inh . infcx . parameter_environment
12111216 }
@@ -1248,6 +1253,21 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12481253 ty
12491254 }
12501255
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+
12511271 fn record_deferred_call_resolution ( & self ,
12521272 closure_def_id : DefId ,
12531273 r : DeferredCallResolutionHandler < ' tcx > ) {
@@ -1593,6 +1613,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15931613 sup : Ty < ' tcx > )
15941614 -> Result < ( ) , TypeError < ' tcx > > {
15951615 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+ } )
15961622 }
15971623
15981624 pub fn mk_eqty ( & self ,
@@ -1602,6 +1628,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16021628 sup : Ty < ' tcx > )
16031629 -> Result < ( ) , TypeError < ' tcx > > {
16041630 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+ } )
16051637 }
16061638
16071639 pub fn mk_subr ( & self ,
@@ -1885,9 +1917,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18851917 Neither => {
18861918 if let Some ( default) = default_map. get ( ty) {
18871919 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 ) {
18911923 Ok ( ( ) ) => { }
18921924 Err ( _) => {
18931925 conflicts. push ( ( * ty, default) ) ;
@@ -1978,9 +2010,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
19782010 Neither => {
19792011 if let Some ( default) = default_map. get ( ty) {
19802012 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 ) {
19842016 Ok ( ( ) ) => { }
19852017 Err ( _) => {
19862018 result = Some ( default) ;
@@ -2880,18 +2912,16 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
28802912 Some ( ref else_expr) => {
28812913 check_expr_with_expectation ( fcx, & else_expr, expected) ;
28822914 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)
28882919 }
28892920 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 ( ) )
28952925 }
28962926 } ;
28972927
@@ -3685,11 +3715,10 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
36853715 Some ( fcx. tcx ( ) . types . err )
36863716 }
36873717 ( 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) )
36933722 }
36943723 _ => None
36953724 } ;
0 commit comments