@@ -39,7 +39,6 @@ use rustc_hir as hir;
39
39
use rustc_hir:: def_id:: LocalDefId ;
40
40
use rustc_hir:: intravisit:: { self , Visitor } ;
41
41
use rustc_hir:: HirId ;
42
- use rustc_infer:: infer:: UpvarRegion ;
43
42
use rustc_middle:: hir:: place:: { Place , PlaceBase , PlaceWithHirId , Projection , ProjectionKind } ;
44
43
use rustc_middle:: mir:: FakeReadCause ;
45
44
use rustc_middle:: traits:: ObligationCauseCode ;
@@ -425,7 +424,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
425
424
self . tcx ,
426
425
upvar_ty,
427
426
capture,
428
- if needs_ref { Some ( closure_env_region) } else { child_capture. region } ,
427
+ if needs_ref {
428
+ closure_env_region
429
+ } else {
430
+ self . tcx . lifetimes . re_erased
431
+ } ,
429
432
) ;
430
433
} ,
431
434
) ,
@@ -587,7 +590,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
587
590
588
591
debug ! ( ?captured_place. place, ?upvar_ty, ?capture, ?captured_place. mutability) ;
589
592
590
- apply_capture_kind_on_capture_ty ( self . tcx , upvar_ty, capture, captured_place. region )
593
+ apply_capture_kind_on_capture_ty (
594
+ self . tcx ,
595
+ upvar_ty,
596
+ capture,
597
+ self . tcx . lifetimes . re_erased ,
598
+ )
591
599
} )
592
600
. collect ( )
593
601
}
@@ -775,13 +783,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
775
783
776
784
let Some ( min_cap_list) = root_var_min_capture_list. get_mut ( & var_hir_id) else {
777
785
let mutability = self . determine_capture_mutability ( & typeck_results, & place) ;
778
- let min_cap_list = vec ! [ ty:: CapturedPlace {
779
- var_ident,
780
- place,
781
- info: capture_info,
782
- mutability,
783
- region: None ,
784
- } ] ;
786
+ let min_cap_list =
787
+ vec ! [ ty:: CapturedPlace { var_ident, place, info: capture_info, mutability } ] ;
785
788
root_var_min_capture_list. insert ( var_hir_id, min_cap_list) ;
786
789
continue ;
787
790
} ;
@@ -874,34 +877,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
874
877
// Only need to insert when we don't have an ancestor in the existing min capture list
875
878
if !ancestor_found {
876
879
let mutability = self . determine_capture_mutability ( & typeck_results, & place) ;
877
- let captured_place = ty:: CapturedPlace {
878
- var_ident,
879
- place,
880
- info : updated_capture_info,
881
- mutability,
882
- region : None ,
883
- } ;
880
+ let captured_place =
881
+ ty:: CapturedPlace { var_ident, place, info : updated_capture_info, mutability } ;
884
882
min_cap_list. push ( captured_place) ;
885
883
}
886
884
}
887
885
888
- // For each capture that is determined to be captured by ref, add region info.
889
- for ( _, captures) in & mut root_var_min_capture_list {
890
- for capture in captures {
891
- match capture. info . capture_kind {
892
- ty:: UpvarCapture :: ByRef ( _) => {
893
- let PlaceBase :: Upvar ( upvar_id) = capture. place . base else {
894
- bug ! ( "expected upvar" )
895
- } ;
896
- let origin = UpvarRegion ( upvar_id, closure_span) ;
897
- let upvar_region = self . next_region_var ( origin) ;
898
- capture. region = Some ( upvar_region) ;
899
- }
900
- _ => ( ) ,
901
- }
902
- }
903
- }
904
-
905
886
debug ! (
906
887
"For closure={:?}, min_captures before sorting={:?}" ,
907
888
closure_def_id, root_var_min_capture_list
@@ -1195,7 +1176,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1195
1176
self . tcx ,
1196
1177
ty,
1197
1178
max_capture_info. capture_kind ,
1198
- Some ( self . tcx . lifetimes . re_erased ) ,
1179
+ self . tcx . lifetimes . re_erased ,
1199
1180
)
1200
1181
}
1201
1182
} ;
@@ -1217,7 +1198,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1217
1198
self . tcx ,
1218
1199
capture. place . ty ( ) ,
1219
1200
capture. info . capture_kind ,
1220
- Some ( self . tcx . lifetimes . re_erased ) ,
1201
+ self . tcx . lifetimes . re_erased ,
1221
1202
) ;
1222
1203
1223
1204
// Checks if a capture implements any of the auto traits
@@ -1935,13 +1916,11 @@ fn apply_capture_kind_on_capture_ty<'tcx>(
1935
1916
tcx : TyCtxt < ' tcx > ,
1936
1917
ty : Ty < ' tcx > ,
1937
1918
capture_kind : UpvarCapture ,
1938
- region : Option < ty:: Region < ' tcx > > ,
1919
+ region : ty:: Region < ' tcx > ,
1939
1920
) -> Ty < ' tcx > {
1940
1921
match capture_kind {
1941
1922
ty:: UpvarCapture :: ByValue => ty,
1942
- ty:: UpvarCapture :: ByRef ( kind) => {
1943
- Ty :: new_ref ( tcx, region. unwrap ( ) , ty, kind. to_mutbl_lossy ( ) )
1944
- }
1923
+ ty:: UpvarCapture :: ByRef ( kind) => Ty :: new_ref ( tcx, region, ty, kind. to_mutbl_lossy ( ) ) ,
1945
1924
}
1946
1925
}
1947
1926
0 commit comments