Skip to content

Commit ed80e8e

Browse files
authored
Rollup merge of #72591 - sexxi-goose:rename_upvar_list-to-closure_captures, r=matthewjasper
librustc_middle: Rename upvar_list to closure_captures As part of supporting RFC 2229, we will be capturing all the places that are mentioned in a closure. Currently the `upvar_list` field gives access to a `FxIndexMap<HirId, Upvar>` map. Eventually this will change, with the `upvar_list` having a more general structure that expresses captured paths, not just the mentioned `upvars`. We will make those changes in subsequent PRs. This commit modifies the name of the `upvar_list` map to `closure_captures` in `TypeckTables`. r? @matthewjasper
2 parents 89cb4d7 + c3dc8c4 commit ed80e8e

File tree

7 files changed

+15
-15
lines changed

7 files changed

+15
-15
lines changed

src/librustc_middle/ty/context.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ pub struct TypeckTables<'tcx> {
419419
/// The upvarID contains the HIR node ID and it also contains the full path
420420
/// leading to the member of the struct or tuple that is used instead of the
421421
/// entire variable.
422-
pub upvar_list: ty::UpvarListMap,
422+
pub closure_captures: ty::UpvarListMap,
423423

424424
/// Stores the type, expression, span and optional scope span of all types
425425
/// that are live across the yield of this generator (if a generator).
@@ -447,7 +447,7 @@ impl<'tcx> TypeckTables<'tcx> {
447447
used_trait_imports: Lrc::new(Default::default()),
448448
tainted_by_errors: None,
449449
concrete_opaque_types: Default::default(),
450-
upvar_list: Default::default(),
450+
closure_captures: Default::default(),
451451
generator_interior_types: Default::default(),
452452
}
453453
}
@@ -688,7 +688,7 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for TypeckTables<'tcx> {
688688
ref used_trait_imports,
689689
tainted_by_errors,
690690
ref concrete_opaque_types,
691-
ref upvar_list,
691+
ref closure_captures,
692692
ref generator_interior_types,
693693
} = *self;
694694

@@ -721,7 +721,7 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for TypeckTables<'tcx> {
721721
used_trait_imports.hash_stable(hcx, hasher);
722722
tainted_by_errors.hash_stable(hcx, hasher);
723723
concrete_opaque_types.hash_stable(hcx, hasher);
724-
upvar_list.hash_stable(hcx, hasher);
724+
closure_captures.hash_stable(hcx, hasher);
725725
generator_interior_types.hash_stable(hcx, hasher);
726726
})
727727
}

src/librustc_mir/borrow_check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ fn do_mir_borrowck<'a, 'tcx>(
142142
infcx.set_tainted_by_errors();
143143
}
144144
let upvars: Vec<_> = tables
145-
.upvar_list
145+
.closure_captures
146146
.get(&def_id.to_def_id())
147147
.into_iter()
148148
.flat_map(|v| v.values())

src/librustc_mir/interpret/validity.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
227227
let mut name = None;
228228
if let Some(def_id) = def_id.as_local() {
229229
let tables = self.ecx.tcx.typeck_tables_of(def_id);
230-
if let Some(upvars) = tables.upvar_list.get(&def_id.to_def_id()) {
230+
if let Some(upvars) = tables.closure_captures.get(&def_id.to_def_id()) {
231231
// Sometimes the index is beyond the number of upvars (seen
232232
// for a generator).
233233
if let Some((&var_hir_id, _)) = upvars.get_index(field) {

src/librustc_mir_build/build/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -790,11 +790,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
790790
let hir_tables = self.hir.tables();
791791

792792
// In analyze_closure() in upvar.rs we gathered a list of upvars used by a
793-
// closure and we stored in a map called upvar_list in TypeckTables indexed
793+
// indexed closure and we stored in a map called closure_captures in TypeckTables
794794
// with the closure's DefId. Here, we run through that vec of UpvarIds for
795795
// the given closure and use the necessary information to create upvar
796796
// debuginfo and to fill `self.upvar_mutbls`.
797-
if let Some(upvars) = hir_tables.upvar_list.get(&fn_def_id) {
797+
if let Some(upvars) = hir_tables.closure_captures.get(&fn_def_id) {
798798
let closure_env_arg = Local::new(1);
799799
let mut closure_env_projs = vec![];
800800
let mut closure_ty = self.local_decls[closure_env_arg].ty;

src/librustc_mir_build/hair/cx/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,7 @@ fn convert_var<'tcx>(
884884
) -> ExprKind<'tcx> {
885885
let upvar_index = cx
886886
.tables()
887-
.upvar_list
887+
.closure_captures
888888
.get(&cx.body_owner)
889889
.and_then(|upvars| upvars.get_full(&var_hir_id).map(|(i, _, _)| i));
890890

src/librustc_typeck/check/upvar.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
112112
};
113113

114114
if let Some(upvars) = self.tcx.upvars_mentioned(closure_def_id) {
115-
let mut upvar_list: FxIndexMap<hir::HirId, ty::UpvarId> =
115+
let mut closure_captures: FxIndexMap<hir::HirId, ty::UpvarId> =
116116
FxIndexMap::with_capacity_and_hasher(upvars.len(), Default::default());
117117
for (&var_hir_id, _) in upvars.iter() {
118118
let upvar_id = ty::UpvarId {
@@ -122,7 +122,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
122122
debug!("seed upvar_id {:?}", upvar_id);
123123
// Adding the upvar Id to the list of Upvars, which will be added
124124
// to the map for the closure at the end of the for loop.
125-
upvar_list.insert(var_hir_id, upvar_id);
125+
closure_captures.insert(var_hir_id, upvar_id);
126126

127127
let capture_kind = match capture_clause {
128128
hir::CaptureBy::Value => ty::UpvarCapture::ByValue,
@@ -140,8 +140,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
140140
// Add the vector of upvars to the map keyed with the closure id.
141141
// This gives us an easier access to them without having to call
142142
// tcx.upvars again..
143-
if !upvar_list.is_empty() {
144-
self.tables.borrow_mut().upvar_list.insert(closure_def_id, upvar_list);
143+
if !closure_captures.is_empty() {
144+
self.tables.borrow_mut().closure_captures.insert(closure_def_id, closure_captures);
145145
}
146146
}
147147

src/librustc_typeck/check/writeback.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
7474
debug!("used_trait_imports({:?}) = {:?}", item_def_id, used_trait_imports);
7575
wbcx.tables.used_trait_imports = used_trait_imports;
7676

77-
wbcx.tables.upvar_list =
78-
mem::replace(&mut self.tables.borrow_mut().upvar_list, Default::default());
77+
wbcx.tables.closure_captures =
78+
mem::replace(&mut self.tables.borrow_mut().closure_captures, Default::default());
7979

8080
if self.is_tainted_by_errors() {
8181
// FIXME(eddyb) keep track of `ErrorReported` from where the error was emitted.

0 commit comments

Comments
 (0)