@@ -10,11 +10,10 @@ use rustc_hir as hir;
1010use rustc_hir:: def:: { CtorKind , DefKind } ;
1111use rustc_hir:: Node ;
1212use rustc_infer:: infer:: { RegionVariableOrigin , TyCtxtInferExt } ;
13- use rustc_infer:: traits:: { Obligation , TraitEngineExt as _ } ;
13+ use rustc_infer:: traits:: Obligation ;
1414use rustc_lint_defs:: builtin:: REPR_TRANSPARENT_EXTERNAL_PRIVATE_FIELDS ;
1515use rustc_middle:: middle:: resolve_bound_vars:: ResolvedArg ;
1616use rustc_middle:: middle:: stability:: EvalResult ;
17- use rustc_middle:: traits:: ObligationCauseCode ;
1817use rustc_middle:: ty:: fold:: BottomUpFolder ;
1918use rustc_middle:: ty:: layout:: { LayoutError , MAX_SIMD_LANES } ;
2019use rustc_middle:: ty:: util:: { Discr , InspectCoroutineFields , IntTypeExt } ;
@@ -24,10 +23,10 @@ use rustc_middle::ty::{
2423} ;
2524use rustc_session:: lint:: builtin:: { UNINHABITED_STATIC , UNSUPPORTED_CALLING_CONVENTIONS } ;
2625use rustc_target:: abi:: FieldIdx ;
26+ use rustc_trait_selection:: traits;
2727use rustc_trait_selection:: traits:: error_reporting:: on_unimplemented:: OnUnimplementedDirective ;
2828use rustc_trait_selection:: traits:: error_reporting:: TypeErrCtxtExt as _;
2929use rustc_trait_selection:: traits:: outlives_bounds:: InferCtxtExt as _;
30- use rustc_trait_selection:: traits:: { self , TraitEngine , TraitEngineExt as _} ;
3130use rustc_type_ir:: fold:: TypeFoldable ;
3231
3332use std:: cell:: LazyCell ;
@@ -1715,55 +1714,31 @@ fn opaque_type_cycle_error(
17151714 err. emit ( )
17161715}
17171716
1718- // FIXME(@lcnr): This should not be computed per coroutine, but instead once for
1719- // each typeck root.
17201717pub ( super ) fn check_coroutine_obligations (
17211718 tcx : TyCtxt < ' _ > ,
17221719 def_id : LocalDefId ,
17231720) -> Result < ( ) , ErrorGuaranteed > {
1724- debug_assert ! ( tcx. is_coroutine ( def_id. to_def_id( ) ) ) ;
1721+ debug_assert ! ( ! tcx. is_typeck_child ( def_id. to_def_id( ) ) ) ;
17251722
1726- let typeck = tcx. typeck ( def_id) ;
1727- let param_env = tcx. param_env ( typeck . hir_owner . def_id ) ;
1723+ let typeck_results = tcx. typeck ( def_id) ;
1724+ let param_env = tcx. param_env ( def_id) ;
17281725
1729- let coroutine_interior_predicates = & typeck. coroutine_interior_predicates [ & def_id] ;
1730- debug ! ( ?coroutine_interior_predicates) ;
1726+ debug ! ( ?typeck_results. coroutine_stalled_predicates) ;
17311727
17321728 let infcx = tcx
17331729 . infer_ctxt ( )
17341730 // typeck writeback gives us predicates with their regions erased.
17351731 // As borrowck already has checked lifetimes, we do not need to do it again.
17361732 . ignoring_regions ( )
1737- // Bind opaque types to type checking root, as they should have been checked by borrowck,
1738- // but may show up in some cases, like when (root) obligations are stalled in the new solver.
1739- . with_opaque_type_inference ( typeck. hir_owner . def_id )
1733+ . with_opaque_type_inference ( def_id)
17401734 . build ( ) ;
17411735
1742- let mut fulfillment_cx = <dyn TraitEngine < ' _ > >:: new ( & infcx) ;
1743- for ( predicate, cause) in coroutine_interior_predicates {
1744- let obligation = Obligation :: new ( tcx, cause. clone ( ) , param_env, * predicate) ;
1745- fulfillment_cx. register_predicate_obligation ( & infcx, obligation) ;
1746- }
1747-
1748- if ( tcx. features ( ) . unsized_locals || tcx. features ( ) . unsized_fn_params )
1749- && let Some ( coroutine) = tcx. mir_coroutine_witnesses ( def_id)
1750- {
1751- for field_ty in coroutine. field_tys . iter ( ) {
1752- fulfillment_cx. register_bound (
1753- & infcx,
1754- param_env,
1755- field_ty. ty ,
1756- tcx. require_lang_item ( hir:: LangItem :: Sized , Some ( field_ty. source_info . span ) ) ,
1757- ObligationCause :: new (
1758- field_ty. source_info . span ,
1759- def_id,
1760- ObligationCauseCode :: SizedCoroutineInterior ( def_id) ,
1761- ) ,
1762- ) ;
1763- }
1736+ let ocx = ObligationCtxt :: new ( & infcx) ;
1737+ for ( predicate, cause) in & typeck_results. coroutine_stalled_predicates {
1738+ ocx. register_obligation ( Obligation :: new ( tcx, cause. clone ( ) , param_env, * predicate) ) ;
17641739 }
17651740
1766- let errors = fulfillment_cx . select_all_or_error ( & infcx ) ;
1741+ let errors = ocx . select_all_or_error ( ) ;
17671742 debug ! ( ?errors) ;
17681743 if !errors. is_empty ( ) {
17691744 return Err ( infcx. err_ctxt ( ) . report_fulfillment_errors ( errors) ) ;
0 commit comments