@@ -10,10 +10,9 @@ 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:: stability:: EvalResult ;
16- use rustc_middle:: traits:: ObligationCauseCode ;
1716use rustc_middle:: ty:: fold:: BottomUpFolder ;
1817use rustc_middle:: ty:: layout:: { LayoutError , MAX_SIMD_LANES } ;
1918use rustc_middle:: ty:: util:: { Discr , InspectCoroutineFields , IntTypeExt } ;
@@ -26,7 +25,7 @@ use rustc_target::abi::FieldIdx;
2625use rustc_trait_selection:: traits:: error_reporting:: on_unimplemented:: OnUnimplementedDirective ;
2726use rustc_trait_selection:: traits:: error_reporting:: TypeErrCtxtExt as _;
2827use rustc_trait_selection:: traits:: outlives_bounds:: InferCtxtExt as _;
29- use rustc_trait_selection:: traits:: { self , TraitEngine , TraitEngineExt as _ } ;
28+ use rustc_trait_selection:: traits:: { self } ;
3029use rustc_type_ir:: fold:: TypeFoldable ;
3130
3231use std:: cell:: LazyCell ;
@@ -1541,55 +1540,31 @@ fn opaque_type_cycle_error(
15411540 err. emit ( )
15421541}
15431542
1544- // FIXME(@lcnr): This should not be computed per coroutine, but instead once for
1545- // each typeck root.
15461543pub ( super ) fn check_coroutine_obligations (
15471544 tcx : TyCtxt < ' _ > ,
15481545 def_id : LocalDefId ,
15491546) -> Result < ( ) , ErrorGuaranteed > {
1550- debug_assert ! ( tcx. is_coroutine ( def_id. to_def_id( ) ) ) ;
1547+ debug_assert ! ( ! tcx. is_typeck_child ( def_id. to_def_id( ) ) ) ;
15511548
1552- let typeck = tcx. typeck ( def_id) ;
1553- let param_env = tcx. param_env ( typeck . hir_owner . def_id ) ;
1549+ let typeck_results = tcx. typeck ( def_id) ;
1550+ let param_env = tcx. param_env ( def_id) ;
15541551
1555- let coroutine_stalled_predicates = & typeck. coroutine_stalled_predicates [ & def_id] ;
1556- debug ! ( ?coroutine_stalled_predicates) ;
1552+ debug ! ( ?typeck_results. coroutine_stalled_predicates) ;
15571553
15581554 let infcx = tcx
15591555 . infer_ctxt ( )
15601556 // typeck writeback gives us predicates with their regions erased.
15611557 // As borrowck already has checked lifetimes, we do not need to do it again.
15621558 . ignoring_regions ( )
1563- // Bind opaque types to type checking root, as they should have been checked by borrowck,
1564- // but may show up in some cases, like when (root) obligations are stalled in the new solver.
1565- . with_opaque_type_inference ( typeck. hir_owner . def_id )
1559+ . with_opaque_type_inference ( def_id)
15661560 . build ( ) ;
15671561
1568- let mut fulfillment_cx = <dyn TraitEngine < ' _ > >:: new ( & infcx) ;
1569- for ( predicate, cause) in coroutine_stalled_predicates {
1570- let obligation = Obligation :: new ( tcx, cause. clone ( ) , param_env, * predicate) ;
1571- fulfillment_cx. register_predicate_obligation ( & infcx, obligation) ;
1572- }
1573-
1574- if ( tcx. features ( ) . unsized_locals || tcx. features ( ) . unsized_fn_params )
1575- && let Some ( coroutine) = tcx. mir_coroutine_witnesses ( def_id)
1576- {
1577- for field_ty in coroutine. field_tys . iter ( ) {
1578- fulfillment_cx. register_bound (
1579- & infcx,
1580- param_env,
1581- field_ty. ty ,
1582- tcx. require_lang_item ( hir:: LangItem :: Sized , Some ( field_ty. source_info . span ) ) ,
1583- ObligationCause :: new (
1584- field_ty. source_info . span ,
1585- def_id,
1586- ObligationCauseCode :: SizedCoroutineInterior ( def_id) ,
1587- ) ,
1588- ) ;
1589- }
1562+ let ocx = ObligationCtxt :: new ( & infcx) ;
1563+ for ( predicate, cause) in & typeck_results. coroutine_stalled_predicates {
1564+ ocx. register_obligation ( Obligation :: new ( tcx, cause. clone ( ) , param_env, * predicate) ) ;
15901565 }
15911566
1592- let errors = fulfillment_cx . select_all_or_error ( & infcx ) ;
1567+ let errors = ocx . select_all_or_error ( ) ;
15931568 debug ! ( ?errors) ;
15941569 if !errors. is_empty ( ) {
15951570 return Err ( infcx. err_ctxt ( ) . report_fulfillment_errors ( errors) ) ;
0 commit comments