@@ -14,7 +14,7 @@ use rustc_hir::{ItemKind, Node, PathSegment};
1414use rustc_infer:: infer:: opaque_types:: ConstrainOpaqueTypeRegionVisitor ;
1515use rustc_infer:: infer:: outlives:: env:: OutlivesEnvironment ;
1616use rustc_infer:: infer:: { DefiningAnchor , RegionVariableOrigin , TyCtxtInferExt } ;
17- use rustc_infer:: traits:: Obligation ;
17+ use rustc_infer:: traits:: { Obligation , TraitEngineExt as _ } ;
1818use rustc_lint:: builtin:: REPR_TRANSPARENT_EXTERNAL_PRIVATE_FIELDS ;
1919use rustc_middle:: hir:: nested_filter;
2020use rustc_middle:: middle:: stability:: EvalResult ;
@@ -28,7 +28,7 @@ use rustc_span::{self, Span};
2828use rustc_target:: spec:: abi:: Abi ;
2929use rustc_trait_selection:: traits:: error_reporting:: on_unimplemented:: OnUnimplementedDirective ;
3030use rustc_trait_selection:: traits:: error_reporting:: TypeErrCtxtExt as _;
31- use rustc_trait_selection:: traits:: { self , ObligationCtxt } ;
31+ use rustc_trait_selection:: traits:: { self , ObligationCtxt , TraitEngine , TraitEngineExt as _ } ;
3232
3333use std:: ops:: ControlFlow ;
3434
@@ -1460,7 +1460,8 @@ fn opaque_type_cycle_error(
14601460 for def_id in visitor. opaques {
14611461 let ty_span = tcx. def_span ( def_id) ;
14621462 if !seen. contains ( & ty_span) {
1463- err. span_label ( ty_span, & format ! ( "returning this opaque type `{ty}`" ) ) ;
1463+ let descr = if ty. is_impl_trait ( ) { "opaque " } else { "" } ;
1464+ err. span_label ( ty_span, & format ! ( "returning this {descr}type `{ty}`" ) ) ;
14641465 seen. insert ( ty_span) ;
14651466 }
14661467 err. span_label ( sp, & format ! ( "returning here with type `{ty}`" ) ) ;
@@ -1507,3 +1508,34 @@ fn opaque_type_cycle_error(
15071508 }
15081509 err. emit ( )
15091510}
1511+
1512+ pub ( super ) fn check_generator_obligations ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) {
1513+ debug_assert ! ( tcx. sess. opts. unstable_opts. drop_tracking_mir) ;
1514+ debug_assert ! ( matches!( tcx. def_kind( def_id) , DefKind :: Generator ) ) ;
1515+
1516+ let typeck = tcx. typeck ( def_id) ;
1517+ let param_env = tcx. param_env ( def_id) ;
1518+
1519+ let generator_interior_predicates = & typeck. generator_interior_predicates [ & def_id] ;
1520+ debug ! ( ?generator_interior_predicates) ;
1521+
1522+ let infcx = tcx
1523+ . infer_ctxt ( )
1524+ // typeck writeback gives us predicates with their regions erased.
1525+ // As borrowck already has checked lifetimes, we do not need to do it again.
1526+ . ignoring_regions ( )
1527+ // Bind opaque types to `def_id` as they should have been checked by borrowck.
1528+ . with_opaque_type_inference ( DefiningAnchor :: Bind ( def_id) )
1529+ . build ( ) ;
1530+
1531+ let mut fulfillment_cx = <dyn TraitEngine < ' _ > >:: new ( infcx. tcx ) ;
1532+ for ( predicate, cause) in generator_interior_predicates {
1533+ let obligation = Obligation :: new ( tcx, cause. clone ( ) , param_env, * predicate) ;
1534+ fulfillment_cx. register_predicate_obligation ( & infcx, obligation) ;
1535+ }
1536+ let errors = fulfillment_cx. select_all_or_error ( & infcx) ;
1537+ debug ! ( ?errors) ;
1538+ if !errors. is_empty ( ) {
1539+ infcx. err_ctxt ( ) . report_fulfillment_errors ( & errors, None ) ;
1540+ }
1541+ }
0 commit comments