Skip to content

Commit 4764093

Browse files
committed
try to improve handling of methods
1 parent b108ac2 commit 4764093

File tree

2 files changed

+31
-14
lines changed

2 files changed

+31
-14
lines changed

src/rustc/middle/borrowck.rs

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import std::list::{list, cons, nil};
1111
import result::{result, ok, err, extensions};
1212
import syntax::print::pprust;
1313
import util::common::indenter;
14+
import ast_util::op_expr_callee_id;
1415

1516
export check_crate, root_map, mutbl_map;
1617

@@ -279,7 +280,7 @@ impl methods for gather_loan_ctxt {
279280
_ {
280281
self.bccx.span_err(
281282
cmt.span,
282-
#fmt["Cannot guarantee the stability \
283+
#fmt["cannot guarantee the stability \
283284
of this expression for the entirety of \
284285
its lifetime, %s",
285286
region_to_str(self.tcx(), scope_r)]);
@@ -927,21 +928,30 @@ impl categorize_methods for borrowck_ctxt {
927928
}
928929
}
929930

930-
fn cat_expr(expr: @ast::expr) -> cmt {
931-
let tcx = self.tcx;
932-
let expr_ty = tcx.ty(expr);
931+
fn cat_method_ref(expr: @ast::expr, expr_ty: ty::t) -> cmt {
932+
@{id:expr.id, span:expr.span,
933+
cat:cat_special(sk_method), lp:none,
934+
mutbl:m_imm, ty:expr_ty}
935+
}
933936

937+
fn cat_rvalue(expr: @ast::expr, expr_ty: ty::t) -> cmt {
938+
@{id:expr.id, span:expr.span,
939+
cat:cat_rvalue, lp:none,
940+
mutbl:m_imm, ty:expr_ty}
941+
}
942+
943+
fn cat_expr(expr: @ast::expr) -> cmt {
934944
#debug["cat_expr: id=%d expr=%s",
935945
expr.id, pprust::expr_to_str(expr)];
936946

937-
if self.method_map.contains_key(expr.id) {
938-
ret @{id:expr.id, span:expr.span,
939-
cat:cat_special(sk_method), lp:none,
940-
mutbl:m_imm, ty:expr_ty};
941-
}
942-
947+
let tcx = self.tcx;
948+
let expr_ty = tcx.ty(expr);
943949
alt expr.node {
944950
ast::expr_unary(ast::deref, e_base) {
951+
if self.method_map.contains_key(expr.id) {
952+
ret self.cat_rvalue(expr, expr_ty);
953+
}
954+
945955
let base_cmt = self.cat_expr(e_base);
946956
alt self.cat_deref(expr, base_cmt, true) {
947957
some(cmt) { ret cmt; }
@@ -955,11 +965,19 @@ impl categorize_methods for borrowck_ctxt {
955965
}
956966

957967
ast::expr_field(base, f_name, _) {
968+
if self.method_map.contains_key(expr.id) {
969+
ret self.cat_method_ref(expr, expr_ty);
970+
}
971+
958972
let base_cmt = self.cat_autoderef(expr, base);
959973
self.cat_field(expr, base_cmt, f_name, expr_ty)
960974
}
961975

962976
ast::expr_index(base, _) {
977+
if self.method_map.contains_key(expr.id) {
978+
ret self.cat_rvalue(expr, expr_ty);
979+
}
980+
963981
self.cat_index(expr, base)
964982
}
965983

@@ -980,9 +998,7 @@ impl categorize_methods for borrowck_ctxt {
980998
ast::expr_block(*) | ast::expr_loop(*) | ast::expr_alt(*) |
981999
ast::expr_lit(*) | ast::expr_break | ast::expr_mac(*) |
9821000
ast::expr_cont | ast::expr_rec(*) {
983-
@{id:expr.id, span:expr.span,
984-
cat:cat_rvalue, lp:none,
985-
mutbl:m_imm, ty:expr_ty}
1001+
ret self.cat_rvalue(expr, expr_ty);
9861002
}
9871003
}
9881004
}

src/rustc/middle/typeck.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2808,7 +2808,8 @@ fn region_of(fcx: @fn_ctxt, expr: @ast::expr) -> ty::region {
28082808
let defn = lookup_def(fcx, path.span, expr.id);
28092809
alt defn {
28102810
ast::def_local(local_id, _) |
2811-
ast::def_upvar(local_id, _, _) {
2811+
ast::def_upvar(local_id, _, _) |
2812+
ast::def_arg(local_id, _) {
28122813
let local_blocks = fcx.ccx.tcx.region_map.local_blocks;
28132814
let local_block_id = local_blocks.get(local_id);
28142815
ty::re_scope(local_block_id)

0 commit comments

Comments
 (0)