@@ -36,6 +36,8 @@ type region_map = {
36
36
local_blocks : hashmap < ast:: node_id , ast:: node_id > ,
37
37
/* Mapping from a region name to its function. */
38
38
region_name_to_fn : hashmap < ast:: def_id , ast:: node_id > ,
39
+ /* Mapping from an AST type node to the region that `&` resolves to in it. */
40
+ ast_type_to_inferred_region : hashmap < ast:: node_id , ty:: region >
39
41
} ;
40
42
41
43
type ctxt = {
@@ -81,33 +83,30 @@ fn scope_contains(region_map: @region_map, superscope: ast::node_id,
81
83
ret true;
82
84
}
83
85
86
+ fn get_inferred_region ( cx : ctxt , sp : syntax:: codemap:: span ) -> ty:: region {
87
+ // We infer to the caller region if we're at item scope
88
+ // and to the block region if we're at block scope.
89
+ //
90
+ // TODO: What do we do if we're in an alt?
91
+
92
+ ret alt cx. parent {
93
+ pa_item ( item_id) | pa_nested_fn ( item_id) {
94
+ ty:: re_caller ( { crate : ast:: local_crate, node: item_id} )
95
+ }
96
+ pa_block ( block_id) { ty:: re_block ( block_id) }
97
+ pa_crate { cx. sess . span_bug ( sp, "inferred region at crate level?!" ) ; }
98
+ }
99
+ }
100
+
84
101
fn resolve_ty ( ty : @ast:: ty , cx : ctxt , visitor : visit:: vt < ctxt > ) {
102
+ let inferred_region = get_inferred_region ( cx, ty. span ) ;
103
+ cx. region_map . ast_type_to_inferred_region . insert ( ty. id , inferred_region) ;
104
+
85
105
alt ty. node {
86
106
ast:: ty_rptr ( { id: region_id, node: node} , _) {
87
107
let region;
88
108
alt node {
89
- ast : : re_inferred {
90
- // We infer to the caller region if we're at item scope
91
- // and to the block region if we're at block scope.
92
- //
93
- // TODO: What do we do if we're in an alt?
94
-
95
- alt cx. parent {
96
- pa_item( item_id) | pa_nested_fn ( item_id) {
97
- let def_id = { crate : ast:: local_crate,
98
- node: item_id} ;
99
- region = ty:: re_caller ( def_id) ;
100
- }
101
- pa_block ( block_id) {
102
- region = ty:: re_block ( block_id) ;
103
- }
104
- pa_crate {
105
- cx. sess . span_bug ( ty. span , "inferred region at " +
106
- "crate level?!" ) ;
107
- }
108
- }
109
- }
110
-
109
+ ast : : re_inferred { region = inferred_region; }
111
110
ast:: re_named ( ident) {
112
111
// If at item scope, introduce or reuse a binding. If at
113
112
// block scope, require that the binding be introduced.
@@ -269,7 +268,9 @@ fn resolve_crate(sess: session, def_map: resolve::def_map, crate: @ast::crate)
269
268
region_map : @{ parents : map:: new_int_hash ( ) ,
270
269
ast_type_to_region : map:: new_int_hash ( ) ,
271
270
local_blocks : map:: new_int_hash ( ) ,
272
- region_name_to_fn : new_def_hash ( ) } ,
271
+ region_name_to_fn : new_def_hash ( ) ,
272
+ ast_type_to_inferred_region :
273
+ map:: new_int_hash ( ) } ,
273
274
mut bindings: @list:: nil,
274
275
mut queued_locals: [ ] ,
275
276
parent: pa_crate,
0 commit comments