@@ -1468,7 +1468,10 @@ fn opaque_type_cycle_error(
1468
1468
err. emit ( )
1469
1469
}
1470
1470
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 > {
1472
1475
debug_assert ! ( matches!( tcx. def_kind( def_id) , DefKind :: Coroutine ) ) ;
1473
1476
1474
1477
let typeck = tcx. typeck ( def_id) ;
@@ -1482,8 +1485,9 @@ pub(super) fn check_coroutine_obligations(tcx: TyCtxt<'_>, def_id: LocalDefId) {
1482
1485
// typeck writeback gives us predicates with their regions erased.
1483
1486
// As borrowck already has checked lifetimes, we do not need to do it again.
1484
1487
. 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 ) )
1487
1491
. build ( ) ;
1488
1492
1489
1493
let mut fulfillment_cx = <dyn TraitEngine < ' _ > >:: new ( & infcx) ;
@@ -1513,6 +1517,16 @@ pub(super) fn check_coroutine_obligations(tcx: TyCtxt<'_>, def_id: LocalDefId) {
1513
1517
let errors = fulfillment_cx. select_all_or_error ( & infcx) ;
1514
1518
debug ! ( ?errors) ;
1515
1519
if !errors. is_empty ( ) {
1516
- infcx. err_ctxt ( ) . report_fulfillment_errors ( errors) ;
1520
+ return Err ( infcx. err_ctxt ( ) . report_fulfillment_errors ( errors) ) ;
1517
1521
}
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 ( ( ) )
1518
1532
}
0 commit comments