Skip to content

Commit 44c100c

Browse files
committed
try to improve handling of methods
1 parent da204e1 commit 44c100c

File tree

1 file changed

+29
-13
lines changed

1 file changed

+29
-13
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

@@ -301,7 +302,7 @@ impl methods for gather_loan_ctxt {
301302
_ {
302303
self.bccx.span_err(
303304
cmt.span,
304-
#fmt["Cannot guarantee the stability \
305+
#fmt["cannot guarantee the stability \
305306
of this expression for the entirety of \
306307
its lifetime, %s",
307308
region_to_str(self.tcx(), scope_r)]);
@@ -989,21 +990,30 @@ impl categorize_methods for borrowck_ctxt {
989990
}
990991
}
991992

992-
fn cat_expr(expr: @ast::expr) -> cmt {
993-
let tcx = self.tcx;
994-
let expr_ty = tcx.ty(expr);
993+
fn cat_method_ref(expr: @ast::expr, expr_ty: ty::t) -> cmt {
994+
@{id:expr.id, span:expr.span,
995+
cat:cat_special(sk_method), lp:none,
996+
mutbl:m_imm, ty:expr_ty}
997+
}
995998

999+
fn cat_rvalue(expr: @ast::expr, expr_ty: ty::t) -> cmt {
1000+
@{id:expr.id, span:expr.span,
1001+
cat:cat_rvalue, lp:none,
1002+
mutbl:m_imm, ty:expr_ty}
1003+
}
1004+
1005+
fn cat_expr(expr: @ast::expr) -> cmt {
9961006
#debug["cat_expr: id=%d expr=%s",
9971007
expr.id, pprust::expr_to_str(expr)];
9981008

999-
if self.method_map.contains_key(expr.id) {
1000-
ret @{id:expr.id, span:expr.span,
1001-
cat:cat_special(sk_method), lp:none,
1002-
mutbl:m_imm, ty:expr_ty};
1003-
}
1004-
1009+
let tcx = self.tcx;
1010+
let expr_ty = tcx.ty(expr);
10051011
alt expr.node {
10061012
ast::expr_unary(ast::deref, e_base) {
1013+
if self.method_map.contains_key(expr.id) {
1014+
ret self.cat_rvalue(expr, expr_ty);
1015+
}
1016+
10071017
let base_cmt = self.cat_expr(e_base);
10081018
alt self.cat_deref(expr, base_cmt, 0u, true) {
10091019
some(cmt) { ret cmt; }
@@ -1017,11 +1027,19 @@ impl categorize_methods for borrowck_ctxt {
10171027
}
10181028

10191029
ast::expr_field(base, f_name, _) {
1030+
if self.method_map.contains_key(expr.id) {
1031+
ret self.cat_method_ref(expr, expr_ty);
1032+
}
1033+
10201034
let base_cmt = self.cat_autoderef(base);
10211035
self.cat_field(expr, base_cmt, f_name)
10221036
}
10231037

10241038
ast::expr_index(base, _) {
1039+
if self.method_map.contains_key(expr.id) {
1040+
ret self.cat_rvalue(expr, expr_ty);
1041+
}
1042+
10251043
self.cat_index(expr, base)
10261044
}
10271045

@@ -1042,9 +1060,7 @@ impl categorize_methods for borrowck_ctxt {
10421060
ast::expr_block(*) | ast::expr_loop(*) | ast::expr_alt(*) |
10431061
ast::expr_lit(*) | ast::expr_break | ast::expr_mac(*) |
10441062
ast::expr_cont | ast::expr_rec(*) {
1045-
@{id:expr.id, span:expr.span,
1046-
cat:cat_rvalue, lp:none,
1047-
mutbl:m_imm, ty:expr_ty}
1063+
ret self.cat_rvalue(expr, expr_ty);
10481064
}
10491065
}
10501066
}

0 commit comments

Comments
 (0)