@@ -633,18 +633,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
633633 let coroutines = std:: mem:: take ( & mut * self . deferred_coroutine_interiors . borrow_mut ( ) ) ;
634634 debug ! ( ?coroutines) ;
635635
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) ;
638640
639641 // Create the `CoroutineWitness` type that we will unify with `interior`.
640642 let args = ty:: GenericArgs :: identity_for_item (
641643 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 ( ) ) ,
643645 ) ;
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) ;
645647
646648 // 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 ;
648650 let ty:: Infer ( ty:: InferTy :: TyVar ( _) ) = interior. kind ( ) else {
649651 span_bug ! ( span, "coroutine interior witness not infer: {:?}" , interior. kind( ) )
650652 } ;
@@ -653,15 +655,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
653655 // Will never define opaque types, as all we do is instantiate a type variable.
654656 . eq ( DefineOpaqueTypes :: Yes , interior, witness)
655657 . expect ( "Failed to unify coroutine interior type" ) ;
656- let mut obligations = ok. obligations ;
657658
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 ( ) {
659664 obligations
660665 . 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) ;
664666 }
667+
668+ self . typeck_results
669+ . borrow_mut ( )
670+ . coroutine_stalled_predicates
671+ . extend ( obligations. into_iter ( ) . map ( |o| ( o. predicate , o. cause ) ) ) ;
665672 }
666673
667674 #[ instrument( skip( self ) , level = "debug" ) ]
0 commit comments