@@ -32,7 +32,7 @@ use std::iter;
32
32
33
33
use crate :: nll:: ToRegionVid ;
34
34
#[ cfg( debug_assertions) ]
35
- use crate :: renumber:: RegionCtxt ;
35
+ use crate :: renumber:: { BoundRegionInfo , RegionCtxt } ;
36
36
use crate :: BorrowckInferCtxt ;
37
37
38
38
#[ derive( Debug ) ]
@@ -446,7 +446,22 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
446
446
|r| {
447
447
debug ! ( ?r) ;
448
448
if !indices. indices . contains_key ( & r) {
449
+ #[ cfg( not( debug_assertions) ) ]
449
450
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
+
450
465
debug ! ( ?region_vid) ;
451
466
indices. insert_late_bound_region ( r, region_vid. to_region_vid ( ) ) ;
452
467
}
@@ -474,7 +489,20 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
474
489
for_each_late_bound_region_in_item ( self . infcx . tcx , self . mir_def . did , |r| {
475
490
debug ! ( ?r) ;
476
491
if !indices. indices . contains_key ( & r) {
492
+ #[ cfg( not( debug_assertions) ) ]
477
493
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
+
478
506
debug ! ( ?region_vid) ;
479
507
indices. insert_late_bound_region ( r, region_vid. to_region_vid ( ) ) ;
480
508
}
@@ -773,7 +801,6 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for BorrowckInferCtxt<'cx, 'tcx> {
773
801
} )
774
802
}
775
803
776
- #[ cfg( not( debug_assertions) ) ]
777
804
#[ instrument( level = "debug" , skip( self , indices) ) ]
778
805
fn replace_bound_regions_with_nll_infer_vars < T > (
779
806
& self ,
@@ -788,39 +815,19 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for BorrowckInferCtxt<'cx, 'tcx> {
788
815
let ( value, _map) = self . tcx . replace_late_bound_regions ( value, |br| {
789
816
debug ! ( ?br) ;
790
817
let liberated_region = self . tcx . mk_re_free ( all_outlive_scope. to_def_id ( ) , br. kind ) ;
818
+ #[ cfg( not( debug_assertions) ) ]
791
819
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
- }
798
820
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
+ } ;
817
827
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) ) )
821
829
} ;
822
830
823
- let region_vid = self . next_nll_region_var ( origin, RegionCtxt :: Bound ( name) ) ;
824
831
indices. insert_late_bound_region ( liberated_region, region_vid. to_region_vid ( ) ) ;
825
832
debug ! ( ?liberated_region, ?region_vid) ;
826
833
region_vid
@@ -837,7 +844,6 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for BorrowckInferCtxt<'cx, 'tcx> {
837
844
/// entries for them and store them in the indices map. This code iterates over the complete
838
845
/// set of late-bound regions and checks for any that we have not yet seen, adding them to the
839
846
/// inputs vector.
840
- #[ cfg( not( debug_assertions) ) ]
841
847
#[ instrument( skip( self , indices) ) ]
842
848
fn replace_late_bound_regions_with_nll_infer_vars_in_recursive_scope (
843
849
& self ,
@@ -847,7 +853,19 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for BorrowckInferCtxt<'cx, 'tcx> {
847
853
for_each_late_bound_region_in_recursive_scope ( self . tcx , mir_def_id, |r| {
848
854
debug ! ( ?r) ;
849
855
if !indices. indices . contains_key ( & r) {
856
+ #[ cfg( not( debug_assertions) ) ]
850
857
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
+
851
869
debug ! ( ?region_vid) ;
852
870
indices. insert_late_bound_region ( r, region_vid. to_region_vid ( ) ) ;
853
871
}
@@ -863,40 +881,19 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for BorrowckInferCtxt<'cx, 'tcx> {
863
881
for_each_late_bound_region_in_item ( self . tcx , mir_def_id, |r| {
864
882
debug ! ( ?r) ;
865
883
if !indices. indices . contains_key ( & r) {
884
+ #[ cfg( not( debug_assertions) ) ]
866
885
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
- }
872
886
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) ) )
896
895
} ;
897
896
898
- let region_vid = self . next_nll_region_var ( FR , RegionCtxt :: LateBound ( name) ) ;
899
- debug ! ( ?region_vid) ;
900
897
indices. insert_late_bound_region ( r, region_vid. to_region_vid ( ) ) ;
901
898
}
902
899
} ) ;
0 commit comments