@@ -1468,7 +1468,10 @@ fn opaque_type_cycle_error(
14681468 err. emit ( )
14691469}
14701470
1471- pub ( super ) fn check_coroutine_obligations ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) {
1471+ pub ( super ) fn check_coroutine_obligations (
1472+ tcx : TyCtxt < ' _ > ,
1473+ def_id : LocalDefId ,
1474+ ) -> Result < ( ) , ErrorGuaranteed > {
14721475 debug_assert ! ( matches!( tcx. def_kind( def_id) , DefKind :: Coroutine ) ) ;
14731476
14741477 let typeck = tcx. typeck ( def_id) ;
@@ -1482,8 +1485,9 @@ pub(super) fn check_coroutine_obligations(tcx: TyCtxt<'_>, def_id: LocalDefId) {
14821485 // typeck writeback gives us predicates with their regions erased.
14831486 // As borrowck already has checked lifetimes, we do not need to do it again.
14841487 . ignoring_regions ( )
1485- // Bind opaque types to `def_id` as they should have been checked by borrowck.
1486- . with_opaque_type_inference ( DefiningAnchor :: Bind ( def_id) )
1488+ // Bind opaque types to type checking root, as they should have been checked by borrowck,
1489+ // but may show up in some cases, like when (root) obligations are stalled in the new solver.
1490+ . with_opaque_type_inference ( DefiningAnchor :: Bind ( typeck. hir_owner . def_id ) )
14871491 . build ( ) ;
14881492
14891493 let mut fulfillment_cx = <dyn TraitEngine < ' _ > >:: new ( & infcx) ;
@@ -1513,6 +1517,16 @@ pub(super) fn check_coroutine_obligations(tcx: TyCtxt<'_>, def_id: LocalDefId) {
15131517 let errors = fulfillment_cx. select_all_or_error ( & infcx) ;
15141518 debug ! ( ?errors) ;
15151519 if !errors. is_empty ( ) {
1516- infcx. err_ctxt ( ) . report_fulfillment_errors ( errors) ;
1520+ return Err ( infcx. err_ctxt ( ) . report_fulfillment_errors ( errors) ) ;
15171521 }
1522+
1523+ // Check that any hidden types found when checking these stalled coroutine obligations
1524+ // are valid.
1525+ for ( key, ty) in infcx. take_opaque_types ( ) {
1526+ let hidden_type = infcx. resolve_vars_if_possible ( ty. hidden_type ) ;
1527+ let key = infcx. resolve_vars_if_possible ( key) ;
1528+ sanity_check_found_hidden_type ( tcx, key, hidden_type) ?;
1529+ }
1530+
1531+ Ok ( ( ) )
15181532}
0 commit comments