@@ -2,17 +2,13 @@ use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
22use rustc_index:: bit_set:: HybridBitSet ;
33use rustc_index:: interval:: IntervalSet ;
44use rustc_infer:: infer:: canonical:: QueryRegionConstraints ;
5- use rustc_infer:: infer:: outlives:: test_type_match;
6- use rustc_infer:: infer:: region_constraints:: VerifyIfEq ;
5+ use rustc_infer:: infer:: opaque_types:: VisitFreeRegionsVisitor ;
76use rustc_middle:: mir:: { BasicBlock , Body , ConstraintCategory , Local , Location } ;
87use rustc_middle:: traits:: query:: DropckOutlivesResult ;
9- use rustc_middle:: ty:: {
10- self , Ty , TyCtxt , TypeSuperVisitable , TypeVisitable , TypeVisitableExt , TypeVisitor ,
11- } ;
8+ use rustc_middle:: ty:: { Ty , TyCtxt , TypeVisitable , TypeVisitableExt } ;
129use rustc_span:: DUMMY_SP ;
1310use rustc_trait_selection:: traits:: query:: type_op:: outlives:: DropckOutlives ;
1411use rustc_trait_selection:: traits:: query:: type_op:: { TypeOp , TypeOpOutput } ;
15- use std:: ops:: ControlFlow ;
1612use std:: rc:: Rc ;
1713
1814use rustc_mir_dataflow:: impls:: MaybeInitializedPlaces ;
@@ -559,99 +555,18 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
559555 "make_all_regions_live: live_at={}" ,
560556 values:: location_set_str( elements, live_at. iter( ) ) ,
561557 ) ;
562-
563- struct MakeAllRegionsLive < ' a , ' b , ' tcx > {
564- typeck : & ' b mut TypeChecker < ' a , ' tcx > ,
565- live_at : & ' b IntervalSet < PointIndex > ,
566- }
567- 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.
576- fn make_alias_live ( & mut self , t : Ty < ' tcx > ) -> ControlFlow < !> {
577- let ty:: Alias ( _kind, alias_ty) = t. kind ( ) else {
578- bug ! ( "`make_alias_live` only takes alias types" ) ;
579- } ;
580- let tcx = self . typeck . infcx . tcx ;
581- let param_env = self . typeck . param_env ;
582- let outlives_bounds: Vec < _ > = tcx
583- . item_bounds ( alias_ty. def_id )
584- . iter_instantiated ( tcx, alias_ty. args )
585- . filter_map ( |clause| {
586- if let Some ( outlives) = clause. as_type_outlives_clause ( )
587- && outlives. skip_binder ( ) . 0 == t
588- {
589- Some ( outlives. skip_binder ( ) . 1 )
590- } else {
591- None
592- }
593- } )
594- . chain ( param_env. caller_bounds ( ) . iter ( ) . filter_map ( |clause| {
595- let outlives = clause. as_type_outlives_clause ( ) ?;
596- if let Some ( outlives) = outlives. no_bound_vars ( )
597- && outlives. 0 == t
598- {
599- Some ( outlives. 1 )
600- } else {
601- test_type_match:: extract_verify_if_eq (
602- tcx,
603- param_env,
604- & outlives. map_bound ( |ty:: OutlivesPredicate ( ty, bound) | {
605- VerifyIfEq { ty, bound }
606- } ) ,
607- t,
608- )
609- }
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)
620- {
621- r. visit_with ( self )
622- } else {
623- t. super_visit_with ( self )
624- }
625- }
626- }
627- impl < ' tcx > TypeVisitor < TyCtxt < ' tcx > > for MakeAllRegionsLive < ' _ , ' _ , ' tcx > {
628- type BreakTy = !;
629-
630- fn visit_region ( & mut self , r : ty:: Region < ' tcx > ) -> ControlFlow < Self :: BreakTy > {
631- if r. is_late_bound ( ) {
632- return ControlFlow :: Continue ( ( ) ) ;
633- }
634- let live_region_vid =
635- self . typeck . borrowck_context . universal_regions . to_region_vid ( r) ;
636- self . typeck
558+ value. visit_with ( & mut VisitFreeRegionsVisitor {
559+ tcx : typeck. tcx ( ) ,
560+ param_env : typeck. param_env ,
561+ op : |r| {
562+ let live_region_vid = typeck. borrowck_context . universal_regions . to_region_vid ( r) ;
563+ typeck
637564 . borrowck_context
638565 . constraints
639566 . liveness_constraints
640- . add_elements ( live_region_vid, self . live_at ) ;
641- ControlFlow :: Continue ( ( ) )
642- }
643-
644- fn visit_ty ( & mut self , t : Ty < ' tcx > ) -> ControlFlow < Self :: BreakTy > {
645- if !t. has_free_regions ( ) {
646- ControlFlow :: Continue ( ( ) )
647- } else if let ty:: Alias ( ..) = t. kind ( ) {
648- self . make_alias_live ( t)
649- } else {
650- t. super_visit_with ( self )
651- }
652- }
653- }
654- value. visit_with ( & mut MakeAllRegionsLive { typeck, live_at } ) ;
567+ . add_elements ( live_region_vid, live_at) ;
568+ } ,
569+ } ) ;
655570 }
656571
657572 fn compute_drop_data (
0 commit comments