Skip to content

Commit e9f54b6

Browse files
committed
Compute upvars lazily.
It can be computed from `tcx` on demand, instead of computing it eagerly and passing it around.
1 parent ef55dc8 commit e9f54b6

File tree

3 files changed

+3
-7
lines changed

3 files changed

+3
-7
lines changed

compiler/rustc_borrowck/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ fn do_mir_borrowck<'tcx>(
217217
&mut flow_inits,
218218
&move_data,
219219
&borrow_set,
220-
tcx.closure_captures(def),
221220
consumer_options,
222221
);
223222

compiler/rustc_borrowck/src/nll.rs

-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ pub(crate) fn compute_regions<'a, 'tcx>(
8585
flow_inits: &mut ResultsCursor<'a, 'tcx, MaybeInitializedPlaces<'a, 'tcx>>,
8686
move_data: &MoveData<'tcx>,
8787
borrow_set: &BorrowSet<'tcx>,
88-
upvars: &[&ty::CapturedPlace<'tcx>],
8988
consumer_options: Option<ConsumerOptions>,
9089
) -> NllOutput<'tcx> {
9190
let is_polonius_legacy_enabled = infcx.tcx.sess.opts.unstable_opts.polonius.is_legacy_enabled();
@@ -112,7 +111,6 @@ pub(crate) fn compute_regions<'a, 'tcx>(
112111
flow_inits,
113112
move_data,
114113
Rc::clone(&elements),
115-
upvars,
116114
);
117115

118116
// Create the region inference context, taking ownership of the

compiler/rustc_borrowck/src/type_check/mod.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ pub(crate) fn type_check<'a, 'tcx>(
128128
flow_inits: &mut ResultsCursor<'a, 'tcx, MaybeInitializedPlaces<'a, 'tcx>>,
129129
move_data: &MoveData<'tcx>,
130130
elements: Rc<DenseLocationMap>,
131-
upvars: &[&ty::CapturedPlace<'tcx>],
132131
) -> MirTypeckResults<'tcx> {
133132
let implicit_region_bound = ty::Region::new_var(infcx.tcx, universal_regions.fr_fn_body);
134133
let mut constraints = MirTypeckRegionConstraints {
@@ -171,7 +170,6 @@ pub(crate) fn type_check<'a, 'tcx>(
171170
all_facts,
172171
borrow_set,
173172
constraints: &mut constraints,
174-
upvars,
175173
};
176174

177175
checker.check_user_type_annotations();
@@ -852,7 +850,6 @@ struct TypeChecker<'a, 'tcx> {
852850
all_facts: &'a mut Option<AllFacts>,
853851
borrow_set: &'a BorrowSet<'tcx>,
854852
constraints: &'a mut MirTypeckRegionConstraints<'tcx>,
855-
upvars: &'a [&'a ty::CapturedPlace<'tcx>],
856853
}
857854

858855
/// Holder struct for passing results from MIR typeck to the rest of the non-lexical regions
@@ -2629,8 +2626,10 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
26292626
);
26302627

26312628
let tcx = self.infcx.tcx;
2629+
let def = self.body.source.def_id().expect_local();
2630+
let upvars = tcx.closure_captures(def);
26322631
let field =
2633-
path_utils::is_upvar_field_projection(tcx, self.upvars, borrowed_place.as_ref(), body);
2632+
path_utils::is_upvar_field_projection(tcx, upvars, borrowed_place.as_ref(), body);
26342633
let category = if let Some(field) = field {
26352634
ConstraintCategory::ClosureUpvar(field)
26362635
} else {

0 commit comments

Comments
 (0)