@@ -565,13 +565,21 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
565565 live_at : & ' b IntervalSet < PointIndex > ,
566566 }
567567 impl < ' tcx > MakeAllRegionsLive < ' _ , ' _ , ' tcx > {
568+ /// We can prove that an alias is live two ways:
569+ /// 1. All the components are live.
570+ /// 2. There is a known outlives bound or where-clause, and that
571+ /// region is live.
572+ /// We search through the item bounds and where clauses for
573+ /// either `'static` or a unique outlives region, and if one is
574+ /// found, we just need to prove that that region is still live.
575+ /// If one is not found, then we continue to walk through the alias.
568576 fn make_alias_live ( & mut self , t : Ty < ' tcx > ) -> ControlFlow < !> {
569577 let ty:: Alias ( _kind, alias_ty) = t. kind ( ) else {
570- bug ! ( ) ;
578+ bug ! ( "`make_alias_live` only takes alias types" ) ;
571579 } ;
572580 let tcx = self . typeck . infcx . tcx ;
573581 let param_env = self . typeck . param_env ;
574- let mut outlives_bounds = tcx
582+ let outlives_bounds: Vec < _ > = tcx
575583 . item_bounds ( alias_ty. def_id )
576584 . iter_instantiated ( tcx, alias_ty. args )
577585 . filter_map ( |clause| {
@@ -599,12 +607,16 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
599607 t,
600608 )
601609 }
602- } ) ) ;
603- if let Some ( r) = outlives_bounds. next ( )
604- && !r. is_late_bound ( )
605- && outlives_bounds. all ( |other_r| {
606- other_r == r
607- } )
610+ } ) )
611+ . collect ( ) ;
612+ // If we find `'static`, then we know the alias doesn't capture *any* regions.
613+ // Otherwise, all of the outlives regions should be equal -- if they're not,
614+ // we don't really know how to proceed, so we continue recursing through the
615+ // alias.
616+ if outlives_bounds. contains ( & tcx. lifetimes . re_static ) {
617+ ControlFlow :: Continue ( ( ) )
618+ } else if let Some ( r) = outlives_bounds. first ( )
619+ && outlives_bounds[ 1 ..] . iter ( ) . all ( |other_r| other_r == r)
608620 {
609621 r. visit_with ( self )
610622 } else {
0 commit comments