@@ -4,15 +4,15 @@ use rustc_hir::def_id::LocalDefId;
44use rustc_hir:: OpaqueTyOrigin ;
55use rustc_infer:: infer:: TyCtxtInferExt as _;
66use rustc_infer:: infer:: { DefiningAnchor , InferCtxt } ;
7- use rustc_infer:: traits:: { Obligation , ObligationCause , TraitEngine } ;
7+ use rustc_infer:: traits:: { Obligation , ObligationCause } ;
88use rustc_middle:: ty:: subst:: { GenericArgKind , InternalSubsts } ;
99use rustc_middle:: ty:: visit:: TypeVisitable ;
1010use rustc_middle:: ty:: {
1111 self , OpaqueHiddenType , OpaqueTypeKey , ToPredicate , Ty , TyCtxt , TypeFoldable ,
1212} ;
1313use rustc_span:: Span ;
1414use rustc_trait_selection:: traits:: error_reporting:: TypeErrCtxtExt as _;
15- use rustc_trait_selection:: traits:: TraitEngineExt as _ ;
15+ use rustc_trait_selection:: traits:: ObligationCtxt ;
1616
1717use super :: RegionInferenceContext ;
1818
@@ -252,48 +252,45 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
252252 // type-alias-impl-trait/issue-67844-nested-opaque.rs
253253 let infcx =
254254 self . tcx . infer_ctxt ( ) . with_opaque_type_inference ( DefiningAnchor :: Bubble ) . build ( ) ;
255+ let ocx = ObligationCtxt :: new ( & infcx) ;
255256 // Require the hidden type to be well-formed with only the generics of the opaque type.
256257 // Defining use functions may have more bounds than the opaque type, which is ok, as long as the
257258 // hidden type is well formed even without those bounds.
258259 let predicate = ty:: Binder :: dummy ( ty:: PredicateKind :: WellFormed ( definition_ty. into ( ) ) )
259260 . to_predicate ( infcx. tcx ) ;
260- let mut fulfillment_cx = <dyn TraitEngine < ' tcx > >:: new ( infcx. tcx ) ;
261261
262262 let id_substs = InternalSubsts :: identity_for_item ( self . tcx , def_id. to_def_id ( ) ) ;
263263
264264 // Require that the hidden type actually fulfills all the bounds of the opaque type, even without
265265 // the bounds that the function supplies.
266266 let opaque_ty = self . tcx . mk_opaque ( def_id. to_def_id ( ) , id_substs) ;
267- match infcx
268- . at ( & ObligationCause :: misc ( instantiated_ty. span , body_id) , param_env)
269- . eq ( opaque_ty, definition_ty)
270- {
271- Ok ( infer_ok) => {
272- for obligation in infer_ok. obligations {
273- fulfillment_cx. register_predicate_obligation ( & infcx, obligation) ;
274- }
275- }
276- Err ( err) => {
277- infcx
278- . err_ctxt ( )
279- . report_mismatched_types (
280- & ObligationCause :: misc ( instantiated_ty. span , body_id) ,
281- opaque_ty,
282- definition_ty,
283- err,
284- )
285- . emit ( ) ;
286- }
267+ if let Err ( err) = ocx. eq (
268+ & ObligationCause :: misc ( instantiated_ty. span , body_id) ,
269+ param_env,
270+ opaque_ty,
271+ definition_ty,
272+ ) {
273+ infcx
274+ . err_ctxt ( )
275+ . report_mismatched_types (
276+ & ObligationCause :: misc ( instantiated_ty. span , body_id) ,
277+ opaque_ty,
278+ definition_ty,
279+ err,
280+ )
281+ . emit ( ) ;
287282 }
288283
289- fulfillment_cx. register_predicate_obligation (
290- & infcx,
291- Obligation :: misc ( instantiated_ty. span , body_id, param_env, predicate) ,
292- ) ;
284+ ocx. register_obligation ( Obligation :: misc (
285+ instantiated_ty. span ,
286+ body_id,
287+ param_env,
288+ predicate,
289+ ) ) ;
293290
294291 // Check that all obligations are satisfied by the implementation's
295292 // version.
296- let errors = fulfillment_cx . select_all_or_error ( & infcx ) ;
293+ let errors = ocx . select_all_or_error ( ) ;
297294
298295 // This is still required for many(half of the tests in ui/type-alias-impl-trait)
299296 // tests to pass
0 commit comments