@@ -132,14 +132,18 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
132
132
} ;
133
133
134
134
self . tcx . with_freevars ( closure_node_id, |freevars| {
135
+ let mut freevar_list: Vec < ty:: UpvarId > = Vec :: with_capacity ( freevars. len ( ) ) ;
135
136
for freevar in freevars {
136
137
let upvar_id = ty:: UpvarId {
137
138
var_path : ty:: UpvarPath {
138
- hir_id : self . tcx . hir ( ) . node_to_hir_id ( freevar. var_id ( ) ) ,
139
+ hir_id : self . tcx . hir ( ) . node_to_hir_id ( freevar. var_id ( ) ) ,
139
140
} ,
140
141
closure_expr_id : LocalDefId :: from_def_id ( closure_def_id) ,
141
142
} ;
142
143
debug ! ( "seed upvar_id {:?}" , upvar_id) ;
144
+ // Adding the upvar Id to the list of Upvars, which will be added
145
+ // to the map for the closure at the end of the for loop.
146
+ freevar_list. push ( upvar_id) ;
143
147
144
148
let capture_kind = match capture_clause {
145
149
hir:: CaptureByValue => ty:: UpvarCapture :: ByValue ,
@@ -159,6 +163,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
159
163
. upvar_capture_map
160
164
. insert ( upvar_id, capture_kind) ;
161
165
}
166
+ // Add the vector of freevars to the map keyed with the closure id.
167
+ // This gives us an easier access to them without having to call
168
+ // with_freevars again..
169
+ self . tables
170
+ . borrow_mut ( )
171
+ . upvar_list
172
+ . insert ( closure_def_id, freevar_list) ;
162
173
} ) ;
163
174
164
175
let body_owner_def_id = self . tcx . hir ( ) . body_owner_def_id ( body. id ( ) ) ;
@@ -176,7 +187,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
176
187
self . param_env ,
177
188
region_scope_tree,
178
189
& self . tables . borrow ( ) ,
179
- ) . consume_body ( body) ;
190
+ )
191
+ . consume_body ( body) ;
180
192
181
193
if let Some ( closure_substs) = infer_kind {
182
194
// Unify the (as yet unbound) type variable in the closure
@@ -250,9 +262,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
250
262
let var_hir_id = tcx. hir ( ) . node_to_hir_id ( var_node_id) ;
251
263
let freevar_ty = self . node_ty ( var_hir_id) ;
252
264
let upvar_id = ty:: UpvarId {
253
- var_path : ty:: UpvarPath {
254
- hir_id : var_hir_id,
255
- } ,
265
+ var_path : ty:: UpvarPath { hir_id : var_hir_id } ,
256
266
closure_expr_id : LocalDefId :: from_def_id ( closure_def_index) ,
257
267
} ;
258
268
let capture = self . tables . borrow ( ) . upvar_capture ( upvar_id) ;
@@ -272,7 +282,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
272
282
} ,
273
283
) ,
274
284
}
275
- } ) . collect ( )
285
+ } )
286
+ . collect ( )
276
287
} )
277
288
}
278
289
}
0 commit comments