@@ -505,13 +505,15 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
505
505
let mut constraints = Default :: default ( ) ;
506
506
let mut liveness_constraints =
507
507
LivenessValues :: without_specific_points ( Rc :: new ( DenseLocationMap :: new ( promoted_body) ) ) ;
508
+ let mut deferred_closure_requirements = Default :: default ( ) ;
508
509
509
510
// Don't try to add borrow_region facts for the promoted MIR as they refer
510
511
// to the wrong locations.
511
512
let mut swap_constraints = |this : & mut Self | {
512
513
mem:: swap ( this. polonius_facts , polonius_facts) ;
513
514
mem:: swap ( & mut this. constraints . outlives_constraints , & mut constraints) ;
514
515
mem:: swap ( & mut this. constraints . liveness_constraints , & mut liveness_constraints) ;
516
+ mem:: swap ( this. deferred_closure_requirements , & mut deferred_closure_requirements) ;
515
517
} ;
516
518
517
519
swap_constraints ( self ) ;
@@ -536,6 +538,17 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
536
538
}
537
539
self . constraints . outlives_constraints . push ( constraint)
538
540
}
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
+
539
552
// If the region is live at least one location in the promoted MIR,
540
553
// then add a liveness constraint to the main MIR for this region
541
554
// at the location provided as an argument to this method
0 commit comments