Skip to content

Commit 2455689

Browse files
committed
---
yaml --- r: 14813 b: refs/heads/try c: 07b4c80 h: refs/heads/master i: 14811: 7936234 v: v3
1 parent 6e67af1 commit 2455689

File tree

2 files changed

+25
-24
lines changed

2 files changed

+25
-24
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
refs/heads/master: 61b1875c16de39c166b0f4d54bba19f9c6777d1a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
5-
refs/heads/try: e54cde52151feabf4dbcd4905f580eeae9a7f28f
5+
refs/heads/try: 07b4c80c68afb015b26041c37b627e5b25c0824b
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/src/rustc/middle/region.rs

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ type region_map = {
3636
local_blocks: hashmap<ast::node_id,ast::node_id>,
3737
/* Mapping from a region name to its function. */
3838
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>
3941
};
4042

4143
type ctxt = {
@@ -81,33 +83,30 @@ fn scope_contains(region_map: @region_map, superscope: ast::node_id,
8183
ret true;
8284
}
8385

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+
84101
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+
85105
alt ty.node {
86106
ast::ty_rptr({id: region_id, node: node}, _) {
87107
let region;
88108
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; }
111110
ast::re_named(ident) {
112111
// If at item scope, introduce or reuse a binding. If at
113112
// 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)
269268
region_map: @{parents: map::new_int_hash(),
270269
ast_type_to_region: map::new_int_hash(),
271270
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()},
273274
mut bindings: @list::nil,
274275
mut queued_locals: [],
275276
parent: pa_crate,

0 commit comments

Comments
 (0)