@@ -20,7 +20,6 @@ use rustc::util::common::ErrorReported;
2020use syntax:: ast;
2121use syntax_pos:: Span ;
2222
23- use super :: assoc;
2423use super :: { Inherited , FnCtxt } ;
2524use astconv:: ExplicitSelf ;
2625
@@ -227,7 +226,6 @@ fn compare_predicate_entailment<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
227226 tcx. infer_ctxt ( trait_param_env, Reveal :: UserFacing ) . enter ( |infcx| {
228227 let inh = Inherited :: new ( infcx) ;
229228 let infcx = & inh. infcx ;
230- let fulfillment_cx = & inh. fulfillment_cx ;
231229
232230 debug ! ( "compare_impl_method: caller_bounds={:?}" ,
233231 infcx. parameter_environment. caller_bounds) ;
@@ -239,12 +237,11 @@ fn compare_predicate_entailment<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
239237 infer:: HigherRankedType ,
240238 & ty:: Binder ( impl_m_own_bounds. predicates ) ) ;
241239 for predicate in impl_m_own_bounds {
242- let traits:: Normalized { value : predicate, .. } =
240+ let traits:: Normalized { value : predicate, obligations } =
243241 traits:: normalize ( & mut selcx, normalize_cause. clone ( ) , & predicate) ;
244242
245- fulfillment_cx. borrow_mut ( ) . register_predicate_obligation (
246- & infcx,
247- traits:: Obligation :: new ( cause. clone ( ) , predicate) ) ;
243+ inh. register_predicates ( obligations) ;
244+ inh. register_predicate ( traits:: Obligation :: new ( cause. clone ( ) , predicate) ) ;
248245 }
249246
250247 // We now need to check that the signature of the impl method is
@@ -277,11 +274,9 @@ fn compare_predicate_entailment<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
277274 let impl_sig =
278275 impl_sig. subst ( tcx, impl_to_skol_substs) ;
279276 let impl_sig =
280- assoc:: normalize_associated_types_in ( & infcx,
281- & mut fulfillment_cx. borrow_mut ( ) ,
282- impl_m_span,
283- impl_m_body_id,
284- & impl_sig) ;
277+ inh. normalize_associated_types_in ( impl_m_span,
278+ impl_m_body_id,
279+ & impl_sig) ;
285280 let impl_fty = tcx. mk_fn_ptr ( ty:: Binder ( impl_sig) ) ;
286281 debug ! ( "compare_impl_method: impl_fty={:?}" , impl_fty) ;
287282
@@ -291,11 +286,9 @@ fn compare_predicate_entailment<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
291286 let trait_sig =
292287 trait_sig. subst ( tcx, trait_to_skol_substs) ;
293288 let trait_sig =
294- assoc:: normalize_associated_types_in ( & infcx,
295- & mut fulfillment_cx. borrow_mut ( ) ,
296- impl_m_span,
297- impl_m_body_id,
298- & trait_sig) ;
289+ inh. normalize_associated_types_in ( impl_m_span,
290+ impl_m_body_id,
291+ & trait_sig) ;
299292 let trait_fty = tcx. mk_fn_ptr ( ty:: Binder ( trait_sig) ) ;
300293
301294 debug ! ( "compare_impl_method: trait_fty={:?}" , trait_fty) ;
@@ -344,7 +337,7 @@ fn compare_predicate_entailment<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
344337
345338 // Check that all obligations are satisfied by the implementation's
346339 // version.
347- if let Err ( ref errors) = fulfillment_cx. borrow_mut ( ) . select_all_or_error ( & infcx) {
340+ if let Err ( ref errors) = inh . fulfillment_cx . borrow_mut ( ) . select_all_or_error ( & infcx) {
348341 infcx. report_fulfillment_errors ( errors) ;
349342 return Err ( ErrorReported ) ;
350343 }
@@ -731,7 +724,8 @@ pub fn compare_const_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
731724 debug ! ( "compare_const_impl(impl_trait_ref={:?})" , impl_trait_ref) ;
732725
733726 tcx. infer_ctxt ( ( ) , Reveal :: UserFacing ) . enter ( |infcx| {
734- let mut fulfillment_cx = traits:: FulfillmentContext :: new ( ) ;
727+ let inh = Inherited :: new ( infcx) ;
728+ let infcx = & inh. infcx ;
735729
736730 // The below is for the most part highly similar to the procedure
737731 // for methods above. It is simpler in many respects, especially
@@ -761,31 +755,21 @@ pub fn compare_const_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
761755 let trait_ty = tcx. item_type ( trait_c. def_id ) . subst ( tcx, trait_to_skol_substs) ;
762756 let mut cause = ObligationCause :: misc ( impl_c_span, impl_c_node_id) ;
763757
764- let err = infcx. commit_if_ok ( |_| {
765- // There is no "body" here, so just pass dummy id.
766- let impl_ty = assoc:: normalize_associated_types_in ( & infcx,
767- & mut fulfillment_cx,
768- impl_c_span,
769- ast:: CRATE_NODE_ID ,
770- & impl_ty) ;
758+ // There is no "body" here, so just pass dummy id.
759+ let impl_ty = inh. normalize_associated_types_in ( impl_c_span,
760+ impl_c_node_id,
761+ & impl_ty) ;
771762
772- debug ! ( "compare_const_impl: impl_ty={:?}" , impl_ty) ;
763+ debug ! ( "compare_const_impl: impl_ty={:?}" , impl_ty) ;
773764
774- let trait_ty = assoc:: normalize_associated_types_in ( & infcx,
775- & mut fulfillment_cx,
776- impl_c_span,
777- ast:: CRATE_NODE_ID ,
778- & trait_ty) ;
765+ let trait_ty = inh. normalize_associated_types_in ( impl_c_span,
766+ impl_c_node_id,
767+ & trait_ty) ;
779768
780- debug ! ( "compare_const_impl: trait_ty={:?}" , trait_ty) ;
769+ debug ! ( "compare_const_impl: trait_ty={:?}" , trait_ty) ;
781770
782- infcx. sub_types ( false , & cause, impl_ty, trait_ty)
783- . map ( |InferOk { obligations, value : ( ) } | {
784- for obligation in obligations {
785- fulfillment_cx. register_predicate_obligation ( & infcx, obligation) ;
786- }
787- } )
788- } ) ;
771+ let err = infcx. sub_types ( false , & cause, impl_ty, trait_ty)
772+ . map ( |ok| inh. register_infer_ok_obligations ( ok) ) ;
789773
790774 if let Err ( terr) = err {
791775 debug ! ( "checking associated const for compatibility: impl ty {:?}, trait ty {:?}" ,
@@ -822,5 +806,7 @@ pub fn compare_const_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
822806 & terr) ;
823807 diag. emit ( ) ;
824808 }
809+
810+ // FIXME(#41323) Check the obligations in the fulfillment context.
825811 } ) ;
826812}
0 commit comments