@@ -32,7 +32,7 @@ use std::iter;
3232
3333use crate :: nll:: ToRegionVid ;
3434#[ cfg( debug_assertions) ]
35- use crate :: renumber:: RegionCtxt ;
35+ use crate :: renumber:: { BoundRegionInfo , RegionCtxt } ;
3636use crate :: BorrowckInferCtxt ;
3737
3838#[ derive( Debug ) ]
@@ -446,7 +446,22 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
446446 |r| {
447447 debug ! ( ?r) ;
448448 if !indices. indices . contains_key ( & r) {
449+ #[ cfg( not( debug_assertions) ) ]
449450 let region_vid = self . infcx . next_nll_region_var ( FR ) ;
451+
452+ #[ cfg( debug_assertions) ]
453+ let region_vid = {
454+ let name = match r. get_name ( ) {
455+ Some ( name) => name,
456+ _ => Symbol :: intern ( "anon" ) ,
457+ } ;
458+
459+ self . infcx . next_nll_region_var (
460+ FR ,
461+ RegionCtxt :: LateBound ( BoundRegionInfo :: Name ( name) ) ,
462+ )
463+ } ;
464+
450465 debug ! ( ?region_vid) ;
451466 indices. insert_late_bound_region ( r, region_vid. to_region_vid ( ) ) ;
452467 }
@@ -474,7 +489,20 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
474489 for_each_late_bound_region_in_item ( self . infcx . tcx , self . mir_def . did , |r| {
475490 debug ! ( ?r) ;
476491 if !indices. indices . contains_key ( & r) {
492+ #[ cfg( not( debug_assertions) ) ]
477493 let region_vid = self . infcx . next_nll_region_var ( FR ) ;
494+
495+ #[ cfg( debug_assertions) ]
496+ let region_vid = {
497+ let name = match r. get_name ( ) {
498+ Some ( name) => name,
499+ _ => Symbol :: intern ( "anon" ) ,
500+ } ;
501+
502+ self . infcx
503+ . next_nll_region_var ( FR , RegionCtxt :: LateBound ( BoundRegionInfo :: Name ( name) ) )
504+ } ;
505+
478506 debug ! ( ?region_vid) ;
479507 indices. insert_late_bound_region ( r, region_vid. to_region_vid ( ) ) ;
480508 }
@@ -773,7 +801,6 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for BorrowckInferCtxt<'cx, 'tcx> {
773801 } )
774802 }
775803
776- #[ cfg( not( debug_assertions) ) ]
777804 #[ instrument( level = "debug" , skip( self , indices) ) ]
778805 fn replace_bound_regions_with_nll_infer_vars < T > (
779806 & self ,
@@ -788,39 +815,19 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for BorrowckInferCtxt<'cx, 'tcx> {
788815 let ( value, _map) = self . tcx . replace_late_bound_regions ( value, |br| {
789816 debug ! ( ?br) ;
790817 let liberated_region = self . tcx . mk_re_free ( all_outlive_scope. to_def_id ( ) , br. kind ) ;
818+ #[ cfg( not( debug_assertions) ) ]
791819 let region_vid = self . next_nll_region_var ( origin) ;
792- indices. insert_late_bound_region ( liberated_region, region_vid. to_region_vid ( ) ) ;
793- debug ! ( ?liberated_region, ?region_vid) ;
794- region_vid
795- } ) ;
796- value
797- }
798820
799- #[ cfg( debug_assertions) ]
800- #[ instrument( level = "debug" , skip( self , indices) ) ]
801- fn replace_bound_regions_with_nll_infer_vars < T > (
802- & self ,
803- origin : NllRegionVariableOrigin ,
804- all_outlive_scope : LocalDefId ,
805- value : ty:: Binder < ' tcx , T > ,
806- indices : & mut UniversalRegionIndices < ' tcx > ,
807- ) -> T
808- where
809- T : TypeFoldable < ' tcx > ,
810- {
811- let ( value, _map) = self . tcx . replace_late_bound_regions ( value, |br| {
812- debug ! ( ?br) ;
813- let liberated_region = self . tcx . mk_region ( ty:: ReFree ( ty:: FreeRegion {
814- scope : all_outlive_scope. to_def_id ( ) ,
815- bound_region : br. kind ,
816- } ) ) ;
821+ #[ cfg( debug_assertions) ]
822+ let region_vid = {
823+ let name = match br. kind . get_name ( ) {
824+ Some ( name) => name,
825+ _ => Symbol :: intern ( "anon" ) ,
826+ } ;
817827
818- let name = match br. kind . get_name ( ) {
819- Some ( name) => name,
820- _ => Symbol :: intern ( "anon" ) ,
828+ self . next_nll_region_var ( origin, RegionCtxt :: Bound ( BoundRegionInfo :: Name ( name) ) )
821829 } ;
822830
823- let region_vid = self . next_nll_region_var ( origin, RegionCtxt :: Bound ( name) ) ;
824831 indices. insert_late_bound_region ( liberated_region, region_vid. to_region_vid ( ) ) ;
825832 debug ! ( ?liberated_region, ?region_vid) ;
826833 region_vid
@@ -837,7 +844,6 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for BorrowckInferCtxt<'cx, 'tcx> {
837844 /// entries for them and store them in the indices map. This code iterates over the complete
838845 /// set of late-bound regions and checks for any that we have not yet seen, adding them to the
839846 /// inputs vector.
840- #[ cfg( not( debug_assertions) ) ]
841847 #[ instrument( skip( self , indices) ) ]
842848 fn replace_late_bound_regions_with_nll_infer_vars_in_recursive_scope (
843849 & self ,
@@ -847,7 +853,19 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for BorrowckInferCtxt<'cx, 'tcx> {
847853 for_each_late_bound_region_in_recursive_scope ( self . tcx , mir_def_id, |r| {
848854 debug ! ( ?r) ;
849855 if !indices. indices . contains_key ( & r) {
856+ #[ cfg( not( debug_assertions) ) ]
850857 let region_vid = self . next_nll_region_var ( FR ) ;
858+
859+ #[ cfg( debug_assertions) ]
860+ let region_vid = {
861+ let name = match r. get_name ( ) {
862+ Some ( name) => name,
863+ _ => Symbol :: intern ( "anon" ) ,
864+ } ;
865+
866+ self . next_nll_region_var ( FR , RegionCtxt :: LateBound ( BoundRegionInfo :: Name ( name) ) )
867+ } ;
868+
851869 debug ! ( ?region_vid) ;
852870 indices. insert_late_bound_region ( r, region_vid. to_region_vid ( ) ) ;
853871 }
@@ -863,40 +881,19 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for BorrowckInferCtxt<'cx, 'tcx> {
863881 for_each_late_bound_region_in_item ( self . tcx , mir_def_id, |r| {
864882 debug ! ( ?r) ;
865883 if !indices. indices . contains_key ( & r) {
884+ #[ cfg( not( debug_assertions) ) ]
866885 let region_vid = self . next_nll_region_var ( FR ) ;
867- debug ! ( ?region_vid) ;
868- indices. insert_late_bound_region ( r, region_vid. to_region_vid ( ) ) ;
869- }
870- } ) ;
871- }
872886
873- /// Finds late-bound regions that do not appear in the parameter listing and adds them to the
874- /// indices vector. Typically, we identify late-bound regions as we process the inputs and
875- /// outputs of the closure/function. However, sometimes there are late-bound regions which do
876- /// not appear in the fn parameters but which are nonetheless in scope. The simplest case of
877- /// this are unused functions, like fn foo<'a>() { } (see e.g., #51351). Despite not being used,
878- /// users can still reference these regions (e.g., let x: &'a u32 = &22;), so we need to create
879- /// entries for them and store them in the indices map. This code iterates over the complete
880- /// set of late-bound regions and checks for any that we have not yet seen, adding them to the
881- /// inputs vector.
882- #[ cfg( debug_assertions) ]
883- #[ instrument( skip( self , indices) ) ]
884- fn replace_late_bound_regions_with_nll_infer_vars (
885- & self ,
886- mir_def_id : LocalDefId ,
887- indices : & mut UniversalRegionIndices < ' tcx > ,
888- ) {
889- let typeck_root_def_id = self . tcx . typeck_root_def_id ( mir_def_id. to_def_id ( ) ) ;
890- for_each_late_bound_region_defined_on ( self . tcx , typeck_root_def_id, |r| {
891- debug ! ( ?r) ;
892- if !indices. indices . contains_key ( & r) {
893- let name = match r. get_name ( ) {
894- Some ( name) => name,
895- _ => Symbol :: intern ( "anon" ) ,
887+ #[ cfg( debug_assertions) ]
888+ let region_vid = {
889+ let name = match r. get_name ( ) {
890+ Some ( name) => name,
891+ _ => Symbol :: intern ( "anon" ) ,
892+ } ;
893+
894+ self . next_nll_region_var ( FR , RegionCtxt :: LateBound ( BoundRegionInfo :: Name ( name) ) )
896895 } ;
897896
898- let region_vid = self . next_nll_region_var ( FR , RegionCtxt :: LateBound ( name) ) ;
899- debug ! ( ?region_vid) ;
900897 indices. insert_late_bound_region ( r, region_vid. to_region_vid ( ) ) ;
901898 }
902899 } ) ;
0 commit comments