@@ -10,11 +10,10 @@ 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:: resolve_bound_vars:: ResolvedArg ;
16
16
use rustc_middle:: middle:: stability:: EvalResult ;
17
- use rustc_middle:: traits:: ObligationCauseCode ;
18
17
use rustc_middle:: ty:: fold:: BottomUpFolder ;
19
18
use rustc_middle:: ty:: layout:: { LayoutError , MAX_SIMD_LANES } ;
20
19
use rustc_middle:: ty:: util:: { Discr , InspectCoroutineFields , IntTypeExt } ;
@@ -24,10 +23,10 @@ use rustc_middle::ty::{
24
23
} ;
25
24
use rustc_session:: lint:: builtin:: { UNINHABITED_STATIC , UNSUPPORTED_CALLING_CONVENTIONS } ;
26
25
use rustc_target:: abi:: FieldIdx ;
26
+ use rustc_trait_selection:: traits;
27
27
use rustc_trait_selection:: traits:: error_reporting:: on_unimplemented:: OnUnimplementedDirective ;
28
28
use rustc_trait_selection:: traits:: error_reporting:: TypeErrCtxtExt as _;
29
29
use rustc_trait_selection:: traits:: outlives_bounds:: InferCtxtExt as _;
30
- use rustc_trait_selection:: traits:: { self , TraitEngine , TraitEngineExt as _} ;
31
30
use rustc_type_ir:: fold:: TypeFoldable ;
32
31
33
32
use std:: cell:: LazyCell ;
@@ -1715,55 +1714,31 @@ fn opaque_type_cycle_error(
1715
1714
err. emit ( )
1716
1715
}
1717
1716
1718
- // FIXME(@lcnr): This should not be computed per coroutine, but instead once for
1719
- // each typeck root.
1720
1717
pub ( super ) fn check_coroutine_obligations (
1721
1718
tcx : TyCtxt < ' _ > ,
1722
1719
def_id : LocalDefId ,
1723
1720
) -> 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( ) ) ) ;
1725
1722
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) ;
1728
1725
1729
- let coroutine_interior_predicates = & typeck. coroutine_interior_predicates [ & def_id] ;
1730
- debug ! ( ?coroutine_interior_predicates) ;
1726
+ debug ! ( ?typeck_results. coroutine_stalled_predicates) ;
1731
1727
1732
1728
let infcx = tcx
1733
1729
. infer_ctxt ( )
1734
1730
// typeck writeback gives us predicates with their regions erased.
1735
1731
// As borrowck already has checked lifetimes, we do not need to do it again.
1736
1732
. 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)
1740
1734
. build ( ) ;
1741
1735
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) ) ;
1764
1739
}
1765
1740
1766
- let errors = fulfillment_cx . select_all_or_error ( & infcx ) ;
1741
+ let errors = ocx . select_all_or_error ( ) ;
1767
1742
debug ! ( ?errors) ;
1768
1743
if !errors. is_empty ( ) {
1769
1744
return Err ( infcx. err_ctxt ( ) . report_fulfillment_errors ( errors) ) ;
0 commit comments