@@ -122,7 +122,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
122
122
} ;
123
123
124
124
self . tcx . with_freevars ( closure_node_id, |freevars| {
125
- let mut freevar_list: Vec < ty:: UpvarId > = Vec :: new ( ) ;
125
+ let mut freevar_list: Vec < ty:: UpvarId > = Vec :: with_capacity ( freevars . len ( ) ) ;
126
126
for freevar in freevars {
127
127
let upvar_id = ty:: UpvarId {
128
128
var_path : ty:: UpvarPath {
@@ -131,6 +131,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
131
131
closure_expr_id : LocalDefId :: from_def_id ( closure_def_id) ,
132
132
} ;
133
133
debug ! ( "seed upvar_id {:?}" , upvar_id) ;
134
+ // Adding the upvar Id to the list of Upvars, which will be added
135
+ // to the map for the closure at the end of the for loop.
134
136
freevar_list. push ( upvar_id) ;
135
137
136
138
let capture_kind = match capture_clause {
@@ -151,6 +153,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
151
153
. upvar_capture_map
152
154
. insert ( upvar_id, capture_kind) ;
153
155
}
156
+ // Add the vector of freevars to the map keyed with the closure id.
157
+ // This gives us an easier access to them without having to call
158
+ // with_freevars again..
154
159
self . tables
155
160
. borrow_mut ( )
156
161
. upvar_list
0 commit comments