@@ -132,7 +132,7 @@ 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 :: new ( ) ;
135
+ let mut freevar_list: Vec < ty:: UpvarId > = Vec :: with_capacity ( freevars . len ( ) ) ;
136
136
for freevar in freevars {
137
137
let upvar_id = ty:: UpvarId {
138
138
var_path : ty:: UpvarPath {
@@ -141,6 +141,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
141
141
closure_expr_id : LocalDefId :: from_def_id ( closure_def_id) ,
142
142
} ;
143
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.
144
146
freevar_list. push ( upvar_id) ;
145
147
146
148
let capture_kind = match capture_clause {
@@ -161,6 +163,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
161
163
. upvar_capture_map
162
164
. insert ( upvar_id, capture_kind) ;
163
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..
164
169
self . tables
165
170
. borrow_mut ( )
166
171
. upvar_list
0 commit comments