@@ -12,6 +12,8 @@ import std::map::hashmap;
12
12
type region_map = {
13
13
/* Mapping from a block to its parent block, if there is one. */
14
14
parent_blocks : hashmap < ast:: node_id , ast:: node_id > ,
15
+ /* Mapping from a lambda to its parent function, if there is one. */
16
+ parent_fns : hashmap < ast:: node_id , ast:: node_id > ,
15
17
/* Mapping from a region type in the AST to its resolved region. */
16
18
ast_type_to_region : hashmap < ast:: node_id , ty:: region > ,
17
19
/* Mapping from a local variable to its containing block. */
@@ -40,7 +42,8 @@ type ctxt = {
40
42
*/
41
43
mut queued_locals : [ ast:: node_id ] ,
42
44
43
- parent : parent
45
+ parent : parent ,
46
+ mut parent_fn : option < ast:: node_id >
44
47
} ;
45
48
46
49
// Returns true if `subblock` is equal to or is lexically nested inside
@@ -206,10 +209,23 @@ fn resolve_pat(pat: @ast::pat, cx: ctxt, visitor: visit::vt<ctxt>) {
206
209
visit:: visit_pat ( pat, cx, visitor) ;
207
210
}
208
211
212
+ fn resolve_expr ( expr : @ast:: expr , cx : ctxt , visitor : visit:: vt < ctxt > ) {
213
+ alt expr. node {
214
+ ast:: expr_fn ( _, _, _, _) | ast:: expr_fn_block ( _, _) {
215
+ let parent_fns = cx. region_map . parent_fns ;
216
+ parent_fns. insert ( expr. id , option:: get ( cx. parent_fn ) ) ;
217
+ let new_cx = { parent_fn : some( expr. id ) with cx} ;
218
+ visit:: visit_expr ( expr, new_cx, visitor) ;
219
+ }
220
+ _ { visit : : visit_expr ( expr, cx, visitor) ; }
221
+ }
222
+ }
223
+
209
224
fn resolve_item ( item : @ast:: item , cx : ctxt , visitor : visit:: vt < ctxt > ) {
210
225
// Items create a new outer block scope as far as we're concerned.
211
226
let new_cx: ctxt = { names_in_scope: map:: new_str_hash ( ) ,
212
- parent: pa_item ( item. id )
227
+ parent: pa_item ( item. id ) ,
228
+ parent_fn: some ( item. id )
213
229
with cx} ;
214
230
visit:: visit_item ( item, new_cx, visitor) ;
215
231
}
@@ -219,17 +235,20 @@ fn resolve_crate(sess: session, def_map: resolve::def_map, crate: @ast::crate)
219
235
let cx: ctxt = { sess: sess,
220
236
def_map: def_map,
221
237
region_map : @{ parent_blocks : map:: new_int_hash ( ) ,
238
+ parent_fns : map:: new_int_hash ( ) ,
222
239
ast_type_to_region : map:: new_int_hash ( ) ,
223
240
local_blocks : map:: new_int_hash ( ) } ,
224
241
names_in_scope: map:: new_str_hash ( ) ,
225
242
mut queued_locals: [ ] ,
226
- parent: pa_crate} ;
243
+ parent: pa_crate,
244
+ mut parent_fn: none} ;
227
245
let visitor = visit:: mk_vt ( @{
228
246
visit_block: resolve_block,
229
247
visit_item: resolve_item,
230
248
visit_ty: resolve_ty,
231
249
visit_arm: resolve_arm,
232
- visit_pat: resolve_pat
250
+ visit_pat: resolve_pat,
251
+ visit_expr: resolve_expr
233
252
with * visit:: default_visitor ( )
234
253
} ) ;
235
254
visit:: visit_crate ( * crate , cx, visitor) ;
0 commit comments