@@ -633,18 +633,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
633
633
let coroutines = std:: mem:: take ( & mut * self . deferred_coroutine_interiors . borrow_mut ( ) ) ;
634
634
debug ! ( ?coroutines) ;
635
635
636
- for & ( expr_def_id, body_id, interior) in coroutines. iter ( ) {
637
- debug ! ( ?expr_def_id) ;
636
+ let mut obligations = vec ! [ ] ;
637
+
638
+ for & ( coroutine_def_id, interior) in coroutines. iter ( ) {
639
+ debug ! ( ?coroutine_def_id) ;
638
640
639
641
// Create the `CoroutineWitness` type that we will unify with `interior`.
640
642
let args = ty:: GenericArgs :: identity_for_item (
641
643
self . tcx ,
642
- self . tcx . typeck_root_def_id ( expr_def_id . to_def_id ( ) ) ,
644
+ self . tcx . typeck_root_def_id ( coroutine_def_id . to_def_id ( ) ) ,
643
645
) ;
644
- let witness = Ty :: new_coroutine_witness ( self . tcx , expr_def_id . to_def_id ( ) , args) ;
646
+ let witness = Ty :: new_coroutine_witness ( self . tcx , coroutine_def_id . to_def_id ( ) , args) ;
645
647
646
648
// Unify `interior` with `witness` and collect all the resulting obligations.
647
- let span = self . tcx . hir_body ( body_id ) . value . span ;
649
+ let span = self . tcx . hir_body_owned_by ( coroutine_def_id ) . value . span ;
648
650
let ty:: Infer ( ty:: InferTy :: TyVar ( _) ) = interior. kind ( ) else {
649
651
span_bug ! ( span, "coroutine interior witness not infer: {:?}" , interior. kind( ) )
650
652
} ;
@@ -653,15 +655,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
653
655
// Will never define opaque types, as all we do is instantiate a type variable.
654
656
. eq ( DefineOpaqueTypes :: Yes , interior, witness)
655
657
. expect ( "Failed to unify coroutine interior type" ) ;
656
- let mut obligations = ok. obligations ;
657
658
658
- // Also collect the obligations that were unstalled by this unification.
659
+ obligations. extend ( ok. obligations ) ;
660
+ }
661
+
662
+ // FIXME: Use a real visitor for unstalled obligations in the new solver.
663
+ if !coroutines. is_empty ( ) {
659
664
obligations
660
665
. extend ( self . fulfillment_cx . borrow_mut ( ) . drain_unstalled_obligations ( & self . infcx ) ) ;
661
-
662
- let obligations = obligations. into_iter ( ) . map ( |o| ( o. predicate , o. cause ) ) ;
663
- self . typeck_results . borrow_mut ( ) . coroutine_stalled_predicates . extend ( obligations) ;
664
666
}
667
+
668
+ self . typeck_results
669
+ . borrow_mut ( )
670
+ . coroutine_stalled_predicates
671
+ . extend ( obligations. into_iter ( ) . map ( |o| ( o. predicate , o. cause ) ) ) ;
665
672
}
666
673
667
674
#[ instrument( skip( self ) , level = "debug" ) ]
0 commit comments