@@ -10,10 +10,9 @@ use rustc_hir as hir;
10
10
use rustc_hir:: def:: { CtorKind , DefKind } ;
11
11
use rustc_hir:: Node ;
12
12
use rustc_infer:: infer:: { RegionVariableOrigin , TyCtxtInferExt } ;
13
- use rustc_infer:: traits:: { Obligation , TraitEngineExt as _ } ;
13
+ use rustc_infer:: traits:: Obligation ;
14
14
use rustc_lint_defs:: builtin:: REPR_TRANSPARENT_EXTERNAL_PRIVATE_FIELDS ;
15
15
use rustc_middle:: middle:: stability:: EvalResult ;
16
- use rustc_middle:: traits:: ObligationCauseCode ;
17
16
use rustc_middle:: ty:: fold:: BottomUpFolder ;
18
17
use rustc_middle:: ty:: layout:: { LayoutError , MAX_SIMD_LANES } ;
19
18
use rustc_middle:: ty:: util:: { Discr , InspectCoroutineFields , IntTypeExt } ;
@@ -26,7 +25,7 @@ use rustc_target::abi::FieldIdx;
26
25
use rustc_trait_selection:: traits:: error_reporting:: on_unimplemented:: OnUnimplementedDirective ;
27
26
use rustc_trait_selection:: traits:: error_reporting:: TypeErrCtxtExt as _;
28
27
use 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 } ;
30
29
use rustc_type_ir:: fold:: TypeFoldable ;
31
30
32
31
use std:: cell:: LazyCell ;
@@ -1541,55 +1540,31 @@ fn opaque_type_cycle_error(
1541
1540
err. emit ( )
1542
1541
}
1543
1542
1544
- // FIXME(@lcnr): This should not be computed per coroutine, but instead once for
1545
- // each typeck root.
1546
1543
pub ( super ) fn check_coroutine_obligations (
1547
1544
tcx : TyCtxt < ' _ > ,
1548
1545
def_id : LocalDefId ,
1549
1546
) -> 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( ) ) ) ;
1551
1548
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) ;
1554
1551
1555
- let coroutine_stalled_predicates = & typeck. coroutine_stalled_predicates [ & def_id] ;
1556
- debug ! ( ?coroutine_stalled_predicates) ;
1552
+ debug ! ( ?typeck_results. coroutine_stalled_predicates) ;
1557
1553
1558
1554
let infcx = tcx
1559
1555
. infer_ctxt ( )
1560
1556
// typeck writeback gives us predicates with their regions erased.
1561
1557
// As borrowck already has checked lifetimes, we do not need to do it again.
1562
1558
. 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)
1566
1560
. build ( ) ;
1567
1561
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) ) ;
1590
1565
}
1591
1566
1592
- let errors = fulfillment_cx . select_all_or_error ( & infcx ) ;
1567
+ let errors = ocx . select_all_or_error ( ) ;
1593
1568
debug ! ( ?errors) ;
1594
1569
if !errors. is_empty ( ) {
1595
1570
return Err ( infcx. err_ctxt ( ) . report_fulfillment_errors ( errors) ) ;
0 commit comments