@@ -5,14 +5,14 @@ use rustc_infer::infer::region_constraints::Constraint;
55use rustc_infer:: infer:: region_constraints:: RegionConstraintData ;
66use rustc_infer:: infer:: RegionVariableOrigin ;
77use rustc_infer:: infer:: { InferCtxt , RegionResolutionError , SubregionOrigin , TyCtxtInferExt as _} ;
8- use rustc_infer:: traits:: { Normalized , ObligationCause , TraitEngine , TraitEngineExt } ;
8+ use rustc_infer:: traits:: ObligationCause ;
99use rustc_middle:: ty:: error:: TypeError ;
1010use rustc_middle:: ty:: RegionVid ;
1111use rustc_middle:: ty:: UniverseIndex ;
1212use rustc_middle:: ty:: { self , Ty , TyCtxt , TypeFoldable } ;
1313use rustc_span:: Span ;
1414use rustc_trait_selection:: traits:: query:: type_op;
15- use rustc_trait_selection:: traits:: { SelectionContext , TraitEngineExt as _ } ;
15+ use rustc_trait_selection:: traits:: ObligationCtxt ;
1616use rustc_traits:: { type_op_ascribe_user_type_with_span, type_op_prove_predicate_with_cause} ;
1717
1818use std:: fmt;
@@ -240,9 +240,9 @@ impl<'tcx> TypeOpInfo<'tcx> for PredicateQuery<'tcx> {
240240 ) -> Option < DiagnosticBuilder < ' tcx , ErrorGuaranteed > > {
241241 let ( ref infcx, key, _) =
242242 mbcx. infcx . tcx . infer_ctxt ( ) . build_with_canonical ( cause. span , & self . canonical_query ) ;
243- let mut fulfill_cx = < dyn TraitEngine < ' _ > > :: new ( infcx. tcx ) ;
244- type_op_prove_predicate_with_cause ( infcx , & mut * fulfill_cx , key, cause) ;
245- try_extract_error_from_fulfill_cx ( fulfill_cx , infcx , placeholder_region, error_region)
243+ let ocx = ObligationCtxt :: new ( infcx) ;
244+ type_op_prove_predicate_with_cause ( & ocx , key, cause) ;
245+ try_extract_error_from_fulfill_cx ( & ocx , placeholder_region, error_region)
246246 }
247247}
248248
@@ -281,9 +281,7 @@ where
281281 ) -> Option < DiagnosticBuilder < ' tcx , ErrorGuaranteed > > {
282282 let ( ref infcx, key, _) =
283283 mbcx. infcx . tcx . infer_ctxt ( ) . build_with_canonical ( cause. span , & self . canonical_query ) ;
284- let mut fulfill_cx = <dyn TraitEngine < ' _ > >:: new ( infcx. tcx ) ;
285-
286- let mut selcx = SelectionContext :: new ( infcx) ;
284+ let ocx = ObligationCtxt :: new ( infcx) ;
287285
288286 // FIXME(lqd): Unify and de-duplicate the following with the actual
289287 // `rustc_traits::type_op::type_op_normalize` query to allow the span we need in the
@@ -292,11 +290,9 @@ where
292290 // to normalize the `nll/relate_tys/impl-fn-ignore-binder-via-bottom.rs` test. Check
293291 // after #85499 lands to see if its fixes have erased this difference.
294292 let ( param_env, value) = key. into_parts ( ) ;
295- let Normalized { value : _, obligations } =
296- rustc_trait_selection:: traits:: normalize ( & mut selcx, param_env, cause, value. value ) ;
297- fulfill_cx. register_predicate_obligations ( infcx, obligations) ;
293+ let _ = ocx. normalize ( cause, param_env, value. value ) ;
298294
299- try_extract_error_from_fulfill_cx ( fulfill_cx , infcx , placeholder_region, error_region)
295+ try_extract_error_from_fulfill_cx ( & ocx , placeholder_region, error_region)
300296 }
301297}
302298
@@ -329,9 +325,9 @@ impl<'tcx> TypeOpInfo<'tcx> for AscribeUserTypeQuery<'tcx> {
329325 ) -> Option < DiagnosticBuilder < ' tcx , ErrorGuaranteed > > {
330326 let ( ref infcx, key, _) =
331327 mbcx. infcx . tcx . infer_ctxt ( ) . build_with_canonical ( cause. span , & self . canonical_query ) ;
332- let mut fulfill_cx = < dyn TraitEngine < ' _ > > :: new ( infcx. tcx ) ;
333- type_op_ascribe_user_type_with_span ( infcx , & mut * fulfill_cx , key, Some ( cause. span ) ) . ok ( ) ?;
334- try_extract_error_from_fulfill_cx ( fulfill_cx , infcx , placeholder_region, error_region)
328+ let ocx = ObligationCtxt :: new ( infcx) ;
329+ type_op_ascribe_user_type_with_span ( & ocx , key, Some ( cause. span ) ) . ok ( ) ?;
330+ try_extract_error_from_fulfill_cx ( & ocx , placeholder_region, error_region)
335331 }
336332}
337333
@@ -372,25 +368,24 @@ impl<'tcx> TypeOpInfo<'tcx> for crate::type_check::InstantiateOpaqueType<'tcx> {
372368 }
373369}
374370
375- #[ instrument( skip( fulfill_cx , infcx ) , level = "debug" ) ]
371+ #[ instrument( skip( ocx ) , level = "debug" ) ]
376372fn try_extract_error_from_fulfill_cx < ' tcx > (
377- mut fulfill_cx : Box < dyn TraitEngine < ' tcx > + ' tcx > ,
378- infcx : & InferCtxt < ' tcx > ,
373+ ocx : & ObligationCtxt < ' _ , ' tcx > ,
379374 placeholder_region : ty:: Region < ' tcx > ,
380375 error_region : Option < ty:: Region < ' tcx > > ,
381376) -> Option < DiagnosticBuilder < ' tcx , ErrorGuaranteed > > {
382377 // We generally shouldn't have errors here because the query was
383378 // already run, but there's no point using `delay_span_bug`
384379 // when we're going to emit an error here anyway.
385- let _errors = fulfill_cx . select_all_or_error ( infcx ) ;
386- let region_constraints = infcx. with_region_constraints ( |r| r. clone ( ) ) ;
380+ let _errors = ocx . select_all_or_error ( ) ;
381+ let region_constraints = ocx . infcx . with_region_constraints ( |r| r. clone ( ) ) ;
387382 try_extract_error_from_region_constraints (
388- infcx,
383+ ocx . infcx ,
389384 placeholder_region,
390385 error_region,
391386 & region_constraints,
392- |vid| infcx. region_var_origin ( vid) ,
393- |vid| infcx. universe_of_region ( infcx. tcx . mk_region ( ty:: ReVar ( vid) ) ) ,
387+ |vid| ocx . infcx . region_var_origin ( vid) ,
388+ |vid| ocx . infcx . universe_of_region ( ocx . infcx . tcx . mk_region ( ty:: ReVar ( vid) ) ) ,
394389 )
395390}
396391
0 commit comments