Skip to content

Commit 28d0ce9

Browse files
committed
fix up handling of &x where x is an arg or &self (for now at least).
1 parent 83a85d7 commit 28d0ce9

File tree

5 files changed

+91
-12
lines changed

5 files changed

+91
-12
lines changed

Makefile.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ STDLIB_INPUTS := $(wildcard $(addprefix $(S)src/libstd/, \
198198
COMPILER_CRATE := $(S)src/rustc/rustc.rc
199199
COMPILER_INPUTS := $(filter-out $(S)src/rustc/driver/rustc.rs, \
200200
$(wildcard $(addprefix $(S)src/rustc/, \
201-
rustc.rc *.rs */*.rs */*/*.rs)))
201+
rustc.rc *.rs */*.rs */*/*.rs */*/*/*.rs)))
202202

203203
LIBRUSTSYNTAX_CRATE := $(S)src/librustsyntax/rustsyntax.rc
204204
LIBRUSTSYNTAX_INPUTS := $(wildcard $(addprefix $(S)src/librustsyntax/, \

src/rustc/middle/typeck/check/regionmanip.rs

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import middle::typeck::infer::{ty_and_region_var_methods};
2+
import syntax::print::pprust::{expr_to_str};
23

34
// Helper functions related to manipulating region types.
45

@@ -113,6 +114,20 @@ fn replace_bound_regions(
113114
* stack position and so the resulting region will be the enclosing block.
114115
*/
115116
fn region_of(fcx: @fn_ctxt, expr: @ast::expr) -> ty::region {
117+
#debug["region_of(expr=%s)", expr_to_str(expr)];
118+
ret alt expr.node {
119+
ast::expr_path(path) {
120+
def(fcx, expr, lookup_def(fcx, path.span, expr.id))}
121+
ast::expr_field(base, _, _) {
122+
deref(fcx, base)}
123+
ast::expr_index(base, _) {
124+
deref(fcx, base)}
125+
ast::expr_unary(ast::deref, base) {
126+
deref(fcx, base)}
127+
_ {
128+
borrow(fcx, expr)}
129+
};
130+
116131
fn borrow(fcx: @fn_ctxt, expr: @ast::expr) -> ty::region {
117132
ty::encl_region(fcx.ccx.tcx, expr.id)
118133
}
@@ -127,24 +142,38 @@ fn region_of(fcx: @fn_ctxt, expr: @ast::expr) -> ty::region {
127142
}
128143
}
129144

130-
alt expr.node {
131-
ast::expr_path(path) {
132-
let defn = lookup_def(fcx, path.span, expr.id);
133-
alt defn {
145+
fn def(fcx: @fn_ctxt, expr: @ast::expr, d: ast::def) -> ty::region {
146+
alt d {
147+
ast::def_arg(local_id, _) |
134148
ast::def_local(local_id, _) |
135-
ast::def_upvar(local_id, _, _) {
149+
ast::def_binding(local_id) {
150+
#debug["region_of.def/arg/local/binding(id=%d)", local_id];
136151
let local_scope = fcx.ccx.tcx.region_map.get(local_id);
137152
ty::re_scope(local_scope)
138153
}
139-
_ {
154+
ast::def_upvar(_, inner, _) {
155+
#debug["region_of.def/upvar"];
156+
def(fcx, expr, *inner)
157+
}
158+
ast::def_self(*) {
159+
alt fcx.in_scope_regions.find(ty::br_self) {
160+
some(r) {r}
161+
none {
162+
// eventually, this should never happen... self should
163+
// always be an &self.T rptr
164+
borrow(fcx, expr)
165+
}
166+
}
167+
}
168+
ast::def_fn(_, _) | ast::def_mod(_) |
169+
ast::def_native_mod(_) | ast::def_const(_) |
170+
ast::def_use(_) | ast::def_variant(_, _) |
171+
ast::def_ty(_) | ast::def_prim_ty(_) |
172+
ast::def_ty_param(_, _) | ast::def_class(_) |
173+
ast::def_region(_) {
140174
ty::re_static
141175
}
142176
}
143-
}
144-
ast::expr_field(base, _, _) { deref(fcx, base) }
145-
ast::expr_index(base, _) { deref(fcx, base) }
146-
ast::expr_unary(ast::deref, base) { deref(fcx, base) }
147-
_ { borrow(fcx, expr) }
148177
}
149178
}
150179

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
fn foo(a: int) {
2+
let _p: &static.int = &a; //! ERROR mismatched types
3+
}
4+
5+
fn bar(a: int) {
6+
let _q: &blk.int = &a;
7+
}
8+
9+
fn main() {
10+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class dog {
2+
let mut cats_chased: uint;
3+
4+
new() {
5+
self.cats_chased = 0u;
6+
}
7+
8+
fn chase_cat() {
9+
let p: &static.mut uint = &mut self.cats_chased; //! ERROR mismatched types
10+
*p += 1u;
11+
}
12+
13+
fn chase_cat_2() {
14+
let p: &blk.mut uint = &mut self.cats_chased;
15+
*p += 1u;
16+
}
17+
}
18+
19+
fn main() {
20+
let d = dog();
21+
d.chase_cat();
22+
#debug["cats_chased: %u", d.cats_chased];
23+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class dog {
2+
let mut food: uint;
3+
4+
new() {
5+
self.food = 0u;
6+
}
7+
8+
fn chase_cat() {
9+
uint::range(0u, 10u) { |i|
10+
let p: &static.mut uint = &mut self.food; //! ERROR mismatched types
11+
*p = 3u;
12+
}
13+
}
14+
}
15+
16+
fn main() {
17+
}

0 commit comments

Comments
 (0)