Skip to content

Commit 445824b

Browse files
author
Ariel Ben-Yehuda
committed
use is_method_call rather than directly accessing the method_map
1 parent 26f0cd5 commit 445824b

File tree

4 files changed

+13
-17
lines changed

4 files changed

+13
-17
lines changed

src/librustc/middle/cfg/construct.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
332332
}
333333

334334
ast::ExprIndex(ref l, ref r) |
335-
ast::ExprBinary(_, ref l, ref r) if self.is_method_call(expr) => {
335+
ast::ExprBinary(_, ref l, ref r) if self.tcx.is_method_call(expr.id) => {
336336
self.call(expr, pred, &**l, Some(&**r).into_iter())
337337
}
338338

@@ -342,7 +342,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
342342
self.straightline(expr, pred, fields)
343343
}
344344

345-
ast::ExprUnary(_, ref e) if self.is_method_call(expr) => {
345+
ast::ExprUnary(_, ref e) if self.tcx.is_method_call(expr.id) => {
346346
self.call(expr, pred, &**e, None::<ast::Expr>.iter())
347347
}
348348

@@ -631,9 +631,4 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
631631
}
632632
}
633633
}
634-
635-
fn is_method_call(&self, expr: &ast::Expr) -> bool {
636-
let method_call = ty::MethodCall::expr(expr.id);
637-
self.tcx.tables.borrow().method_map.contains_key(&method_call)
638-
}
639634
}

src/librustc/middle/ty.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6631,6 +6631,11 @@ impl<'tcx> ctxt<'tcx> {
66316631
self.tables.borrow().method_map.contains_key(&MethodCall::expr(expr_id))
66326632
}
66336633

6634+
pub fn is_overloaded_autoderef(&self, expr_id: ast::NodeId, autoderefs: u32) -> bool {
6635+
self.tables.borrow().method_map.contains_key(&MethodCall::autoderef(expr_id,
6636+
autoderefs))
6637+
}
6638+
66346639
pub fn upvar_capture(&self, upvar_id: ty::UpvarId) -> Option<ty::UpvarCapture> {
66356640
Some(self.tables.borrow().upvar_capture_map.get(&upvar_id).unwrap().clone())
66366641
}

src/librustc_trans/trans/expr.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,7 @@ fn apply_adjustments<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
367367
match datum.ty.sty {
368368
// Don't skip a conversion from Box<T> to &T, etc.
369369
ty::TyRef(..) => {
370-
let method_call = MethodCall::autoderef(expr.id, 0);
371-
if bcx.tcx().tables.borrow().method_map.contains_key(&method_call) {
370+
if bcx.tcx().is_overloaded_autoderef(expr.id, 0) {
372371
// Don't skip an overloaded deref.
373372
0
374373
} else {
@@ -1612,9 +1611,7 @@ fn trans_unary<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
16121611
// The only overloaded operator that is translated to a datum
16131612
// is an overloaded deref, since it is always yields a `&T`.
16141613
// Otherwise, we should be in the RvalueDpsExpr path.
1615-
assert!(
1616-
op == ast::UnDeref ||
1617-
!ccx.tcx().tables.borrow().method_map.contains_key(&method_call));
1614+
assert!(op == ast::UnDeref || !ccx.tcx().is_method_call(expr.id));
16181615

16191616
let un_ty = expr_ty(bcx, expr);
16201617

@@ -1907,7 +1904,7 @@ fn trans_binary<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
19071904
let ccx = bcx.ccx();
19081905

19091906
// if overloaded, would be RvalueDpsExpr
1910-
assert!(!ccx.tcx().tables.borrow().method_map.contains_key(&MethodCall::expr(expr.id)));
1907+
assert!(!ccx.tcx().is_method_call(expr.id));
19111908

19121909
match op.node {
19131910
ast::BiAnd => {
@@ -2141,7 +2138,7 @@ fn trans_assign_op<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
21412138
debug!("trans_assign_op(expr={:?})", expr);
21422139

21432140
// User-defined operator methods cannot be used with `+=` etc right now
2144-
assert!(!bcx.tcx().tables.borrow().method_map.contains_key(&MethodCall::expr(expr.id)));
2141+
assert!(!bcx.tcx().is_method_call(expr.id));
21452142

21462143
// Evaluate LHS (destination), which should be an lvalue
21472144
let dst_datum = unpack_datum!(bcx, trans_to_lvalue(bcx, dst, "assign_op"));
@@ -2606,7 +2603,7 @@ enum ExprKind {
26062603
}
26072604

26082605
fn expr_kind(tcx: &ty::ctxt, expr: &ast::Expr) -> ExprKind {
2609-
if tcx.tables.borrow().method_map.contains_key(&MethodCall::expr(expr.id)) {
2606+
if tcx.is_method_call(expr.id) {
26102607
// Overloaded operations are generally calls, and hence they are
26112608
// generated via DPS, but there are a few exceptions:
26122609
return match expr.node {

src/librustc_typeck/check/regionck.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -516,8 +516,7 @@ fn visit_expr(rcx: &mut Rcx, expr: &ast::Expr) {
516516
type_must_outlive(rcx, infer::ExprTypeIsNotInScope(expr_ty, expr.span),
517517
expr_ty, ty::ReScope(CodeExtent::from_node_id(expr.id)));
518518

519-
let method_call = MethodCall::expr(expr.id);
520-
let has_method_map = rcx.fcx.inh.tables.borrow().method_map.contains_key(&method_call);
519+
let has_method_map = rcx.fcx.infcx().is_method_call(expr.id);
521520

522521
// Check any autoderefs or autorefs that appear.
523522
let adjustment = rcx.fcx.inh.tables.borrow().adjustments.get(&expr.id).map(|a| a.clone());

0 commit comments

Comments
 (0)