@@ -20,7 +20,6 @@ use rustc::util::common::ErrorReported;
20
20
use syntax:: ast;
21
21
use syntax_pos:: Span ;
22
22
23
- use super :: assoc;
24
23
use super :: { Inherited , FnCtxt } ;
25
24
use astconv:: ExplicitSelf ;
26
25
@@ -227,7 +226,6 @@ fn compare_predicate_entailment<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
227
226
tcx. infer_ctxt ( trait_param_env, Reveal :: UserFacing ) . enter ( |infcx| {
228
227
let inh = Inherited :: new ( infcx) ;
229
228
let infcx = & inh. infcx ;
230
- let fulfillment_cx = & inh. fulfillment_cx ;
231
229
232
230
debug ! ( "compare_impl_method: caller_bounds={:?}" ,
233
231
infcx. parameter_environment. caller_bounds) ;
@@ -239,12 +237,11 @@ fn compare_predicate_entailment<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
239
237
infer:: HigherRankedType ,
240
238
& ty:: Binder ( impl_m_own_bounds. predicates ) ) ;
241
239
for predicate in impl_m_own_bounds {
242
- let traits:: Normalized { value : predicate, .. } =
240
+ let traits:: Normalized { value : predicate, obligations } =
243
241
traits:: normalize ( & mut selcx, normalize_cause. clone ( ) , & predicate) ;
244
242
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) ) ;
248
245
}
249
246
250
247
// 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>,
277
274
let impl_sig =
278
275
impl_sig. subst ( tcx, impl_to_skol_substs) ;
279
276
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) ;
285
280
let impl_fty = tcx. mk_fn_ptr ( ty:: Binder ( impl_sig) ) ;
286
281
debug ! ( "compare_impl_method: impl_fty={:?}" , impl_fty) ;
287
282
@@ -291,11 +286,9 @@ fn compare_predicate_entailment<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
291
286
let trait_sig =
292
287
trait_sig. subst ( tcx, trait_to_skol_substs) ;
293
288
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) ;
299
292
let trait_fty = tcx. mk_fn_ptr ( ty:: Binder ( trait_sig) ) ;
300
293
301
294
debug ! ( "compare_impl_method: trait_fty={:?}" , trait_fty) ;
@@ -344,7 +337,7 @@ fn compare_predicate_entailment<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
344
337
345
338
// Check that all obligations are satisfied by the implementation's
346
339
// 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) {
348
341
infcx. report_fulfillment_errors ( errors) ;
349
342
return Err ( ErrorReported ) ;
350
343
}
@@ -731,7 +724,8 @@ pub fn compare_const_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
731
724
debug ! ( "compare_const_impl(impl_trait_ref={:?})" , impl_trait_ref) ;
732
725
733
726
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 ;
735
729
736
730
// The below is for the most part highly similar to the procedure
737
731
// 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>,
761
755
let trait_ty = tcx. item_type ( trait_c. def_id ) . subst ( tcx, trait_to_skol_substs) ;
762
756
let mut cause = ObligationCause :: misc ( impl_c_span, impl_c_node_id) ;
763
757
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) ;
771
762
772
- debug ! ( "compare_const_impl: impl_ty={:?}" , impl_ty) ;
763
+ debug ! ( "compare_const_impl: impl_ty={:?}" , impl_ty) ;
773
764
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) ;
779
768
780
- debug ! ( "compare_const_impl: trait_ty={:?}" , trait_ty) ;
769
+ debug ! ( "compare_const_impl: trait_ty={:?}" , trait_ty) ;
781
770
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) ) ;
789
773
790
774
if let Err ( terr) = err {
791
775
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>,
822
806
& terr) ;
823
807
diag. emit ( ) ;
824
808
}
809
+
810
+ // FIXME(#41323) Check the obligations in the fulfillment context.
825
811
} ) ;
826
812
}
0 commit comments