@@ -505,13 +505,15 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
505505 let mut constraints = Default :: default ( ) ;
506506 let mut liveness_constraints =
507507 LivenessValues :: without_specific_points ( Rc :: new ( DenseLocationMap :: new ( promoted_body) ) ) ;
508+ let mut deferred_closure_requirements = Default :: default ( ) ;
508509
509510 // Don't try to add borrow_region facts for the promoted MIR as they refer
510511 // to the wrong locations.
511512 let mut swap_constraints = |this : & mut Self | {
512513 mem:: swap ( this. polonius_facts , polonius_facts) ;
513514 mem:: swap ( & mut this. constraints . outlives_constraints , & mut constraints) ;
514515 mem:: swap ( & mut this. constraints . liveness_constraints , & mut liveness_constraints) ;
516+ mem:: swap ( this. deferred_closure_requirements , & mut deferred_closure_requirements) ;
515517 } ;
516518
517519 swap_constraints ( self ) ;
@@ -536,6 +538,17 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
536538 }
537539 self . constraints . outlives_constraints . push ( constraint)
538540 }
541+
542+ // If there are nested bodies in promoteds, we also need to update their
543+ // location to something in the actually body, not the promoted.
544+ //
545+ // We don't update the constraint categories of the resulting constraints
546+ // as returns in nested bodies are a proper return, even if that nested body
547+ // is in a promoted.
548+ for ( closure_def_id, args, _locations) in deferred_closure_requirements {
549+ self . deferred_closure_requirements . push ( ( closure_def_id, args, locations) ) ;
550+ }
551+
539552 // If the region is live at least one location in the promoted MIR,
540553 // then add a liveness constraint to the main MIR for this region
541554 // at the location provided as an argument to this method
0 commit comments