Skip to content

Commit 9936179

Browse files
Rollup merge of rust-lang#129987 - compiler-errors:capture-place-region, r=davidtwco
Don't store region in `CapturedPlace` It's not necessary anymore, since we erase all regions in writeback anyways.
2 parents bc2244f + e04ede4 commit 9936179

File tree

2 files changed

+19
-43
lines changed

2 files changed

+19
-43
lines changed

compiler/rustc_hir_typeck/src/upvar.rs

+19-40
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ use rustc_hir as hir;
3939
use rustc_hir::def_id::LocalDefId;
4040
use rustc_hir::intravisit::{self, Visitor};
4141
use rustc_hir::HirId;
42-
use rustc_infer::infer::UpvarRegion;
4342
use rustc_middle::hir::place::{Place, PlaceBase, PlaceWithHirId, Projection, ProjectionKind};
4443
use rustc_middle::mir::FakeReadCause;
4544
use rustc_middle::traits::ObligationCauseCode;
@@ -425,7 +424,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
425424
self.tcx,
426425
upvar_ty,
427426
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+
},
429432
);
430433
},
431434
),
@@ -587,7 +590,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
587590

588591
debug!(?captured_place.place, ?upvar_ty, ?capture, ?captured_place.mutability);
589592

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+
)
591599
})
592600
.collect()
593601
}
@@ -775,13 +783,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
775783

776784
let Some(min_cap_list) = root_var_min_capture_list.get_mut(&var_hir_id) else {
777785
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 }];
785788
root_var_min_capture_list.insert(var_hir_id, min_cap_list);
786789
continue;
787790
};
@@ -874,34 +877,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
874877
// Only need to insert when we don't have an ancestor in the existing min capture list
875878
if !ancestor_found {
876879
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 };
884882
min_cap_list.push(captured_place);
885883
}
886884
}
887885

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-
905886
debug!(
906887
"For closure={:?}, min_captures before sorting={:?}",
907888
closure_def_id, root_var_min_capture_list
@@ -1195,7 +1176,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11951176
self.tcx,
11961177
ty,
11971178
max_capture_info.capture_kind,
1198-
Some(self.tcx.lifetimes.re_erased),
1179+
self.tcx.lifetimes.re_erased,
11991180
)
12001181
}
12011182
};
@@ -1217,7 +1198,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12171198
self.tcx,
12181199
capture.place.ty(),
12191200
capture.info.capture_kind,
1220-
Some(self.tcx.lifetimes.re_erased),
1201+
self.tcx.lifetimes.re_erased,
12211202
);
12221203

12231204
// Checks if a capture implements any of the auto traits
@@ -1935,13 +1916,11 @@ fn apply_capture_kind_on_capture_ty<'tcx>(
19351916
tcx: TyCtxt<'tcx>,
19361917
ty: Ty<'tcx>,
19371918
capture_kind: UpvarCapture,
1938-
region: Option<ty::Region<'tcx>>,
1919+
region: ty::Region<'tcx>,
19391920
) -> Ty<'tcx> {
19401921
match capture_kind {
19411922
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()),
19451924
}
19461925
}
19471926

compiler/rustc_middle/src/ty/closure.rs

-3
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,6 @@ pub struct CapturedPlace<'tcx> {
8888

8989
/// Represents if `place` can be mutated or not.
9090
pub mutability: hir::Mutability,
91-
92-
/// Region of the resulting reference if the upvar is captured by ref.
93-
pub region: Option<ty::Region<'tcx>>,
9491
}
9592

9693
impl<'tcx> CapturedPlace<'tcx> {

0 commit comments

Comments
 (0)