Skip to content

Commit 237ad12

Browse files
committed
Use closure_min_captures in borrow checker
- Use closure_min_captures to generate the Upvar structure that stores information for diagnostics and information about mutability of captures.
1 parent e2efdd1 commit 237ad12

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

compiler/rustc_mir/src/borrow_check/mod.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use rustc_hir::{HirId, Node};
99
use rustc_index::bit_set::BitSet;
1010
use rustc_index::vec::IndexVec;
1111
use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
12+
use rustc_middle::hir::place::PlaceBase as HirPlaceBase;
1213
use rustc_middle::mir::{
1314
traversal, Body, ClearCrossCrate, Local, Location, Mutability, Operand, Place, PlaceElem,
1415
PlaceRef,
@@ -75,6 +76,7 @@ crate use region_infer::RegionInferenceContext;
7576
crate struct Upvar {
7677
name: Symbol,
7778

79+
// FIXME(project-rfc-2229#8): This should use Place or something similar
7880
var_hir_id: HirId,
7981

8082
/// If true, the capture is behind a reference.
@@ -155,13 +157,13 @@ fn do_mir_borrowck<'a, 'tcx>(
155157
infcx.set_tainted_by_errors();
156158
}
157159
let upvars: Vec<_> = tables
158-
.closure_captures
159-
.get(&def.did.to_def_id())
160-
.into_iter()
161-
.flat_map(|v| v.values())
162-
.map(|upvar_id| {
163-
let var_hir_id = upvar_id.var_path.hir_id;
164-
let capture = tables.upvar_capture(*upvar_id);
160+
.closure_min_captures_flattened(def.did.to_def_id())
161+
.map(|captured_place| {
162+
let var_hir_id = match captured_place.place.base {
163+
HirPlaceBase::Upvar(upvar_id) => upvar_id.var_path.hir_id,
164+
_ => bug!("Expected upvar"),
165+
};
166+
let capture = captured_place.info.capture_kind;
165167
let by_ref = match capture {
166168
ty::UpvarCapture::ByValue(_) => false,
167169
ty::UpvarCapture::ByRef(..) => true,

compiler/rustc_mir/src/borrow_check/type_check/mod.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,11 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
749749
(&adt_def.variants[VariantIdx::new(0)], substs)
750750
}
751751
ty::Closure(_, substs) => {
752-
return match substs.as_closure().upvar_tys().nth(field.index()) {
752+
return match substs
753+
.as_closure()
754+
.tupled_upvars_ty()
755+
.tuple_element_ty(field.index())
756+
{
753757
Some(ty) => Ok(ty),
754758
None => Err(FieldAccessError::OutOfRange {
755759
field_count: substs.as_closure().upvar_tys().count(),

0 commit comments

Comments
 (0)