1
Fork 0

use is_method_call rather than directly accessing the method_map

This commit is contained in:
Ariel Ben-Yehuda 2015-07-07 18:45:21 +03:00
parent 26f0cd5de7
commit 445824b29f
4 changed files with 13 additions and 17 deletions

View file

@ -332,7 +332,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
} }
ast::ExprIndex(ref l, ref r) | ast::ExprIndex(ref l, ref r) |
ast::ExprBinary(_, ref l, ref r) if self.is_method_call(expr) => { ast::ExprBinary(_, ref l, ref r) if self.tcx.is_method_call(expr.id) => {
self.call(expr, pred, &**l, Some(&**r).into_iter()) self.call(expr, pred, &**l, Some(&**r).into_iter())
} }
@ -342,7 +342,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
self.straightline(expr, pred, fields) self.straightline(expr, pred, fields)
} }
ast::ExprUnary(_, ref e) if self.is_method_call(expr) => { ast::ExprUnary(_, ref e) if self.tcx.is_method_call(expr.id) => {
self.call(expr, pred, &**e, None::<ast::Expr>.iter()) self.call(expr, pred, &**e, None::<ast::Expr>.iter())
} }
@ -631,9 +631,4 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
} }
} }
} }
fn is_method_call(&self, expr: &ast::Expr) -> bool {
let method_call = ty::MethodCall::expr(expr.id);
self.tcx.tables.borrow().method_map.contains_key(&method_call)
}
} }

View file

@ -6631,6 +6631,11 @@ impl<'tcx> ctxt<'tcx> {
self.tables.borrow().method_map.contains_key(&MethodCall::expr(expr_id)) self.tables.borrow().method_map.contains_key(&MethodCall::expr(expr_id))
} }
pub fn is_overloaded_autoderef(&self, expr_id: ast::NodeId, autoderefs: u32) -> bool {
self.tables.borrow().method_map.contains_key(&MethodCall::autoderef(expr_id,
autoderefs))
}
pub fn upvar_capture(&self, upvar_id: ty::UpvarId) -> Option<ty::UpvarCapture> { pub fn upvar_capture(&self, upvar_id: ty::UpvarId) -> Option<ty::UpvarCapture> {
Some(self.tables.borrow().upvar_capture_map.get(&upvar_id).unwrap().clone()) Some(self.tables.borrow().upvar_capture_map.get(&upvar_id).unwrap().clone())
} }

View file

@ -367,8 +367,7 @@ fn apply_adjustments<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
match datum.ty.sty { match datum.ty.sty {
// Don't skip a conversion from Box<T> to &T, etc. // Don't skip a conversion from Box<T> to &T, etc.
ty::TyRef(..) => { ty::TyRef(..) => {
let method_call = MethodCall::autoderef(expr.id, 0); if bcx.tcx().is_overloaded_autoderef(expr.id, 0) {
if bcx.tcx().tables.borrow().method_map.contains_key(&method_call) {
// Don't skip an overloaded deref. // Don't skip an overloaded deref.
0 0
} else { } else {
@ -1612,9 +1611,7 @@ fn trans_unary<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
// The only overloaded operator that is translated to a datum // The only overloaded operator that is translated to a datum
// is an overloaded deref, since it is always yields a `&T`. // is an overloaded deref, since it is always yields a `&T`.
// Otherwise, we should be in the RvalueDpsExpr path. // Otherwise, we should be in the RvalueDpsExpr path.
assert!( assert!(op == ast::UnDeref || !ccx.tcx().is_method_call(expr.id));
op == ast::UnDeref ||
!ccx.tcx().tables.borrow().method_map.contains_key(&method_call));
let un_ty = expr_ty(bcx, expr); let un_ty = expr_ty(bcx, expr);
@ -1907,7 +1904,7 @@ fn trans_binary<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
let ccx = bcx.ccx(); let ccx = bcx.ccx();
// if overloaded, would be RvalueDpsExpr // if overloaded, would be RvalueDpsExpr
assert!(!ccx.tcx().tables.borrow().method_map.contains_key(&MethodCall::expr(expr.id))); assert!(!ccx.tcx().is_method_call(expr.id));
match op.node { match op.node {
ast::BiAnd => { ast::BiAnd => {
@ -2141,7 +2138,7 @@ fn trans_assign_op<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
debug!("trans_assign_op(expr={:?})", expr); debug!("trans_assign_op(expr={:?})", expr);
// User-defined operator methods cannot be used with `+=` etc right now // User-defined operator methods cannot be used with `+=` etc right now
assert!(!bcx.tcx().tables.borrow().method_map.contains_key(&MethodCall::expr(expr.id))); assert!(!bcx.tcx().is_method_call(expr.id));
// Evaluate LHS (destination), which should be an lvalue // Evaluate LHS (destination), which should be an lvalue
let dst_datum = unpack_datum!(bcx, trans_to_lvalue(bcx, dst, "assign_op")); let dst_datum = unpack_datum!(bcx, trans_to_lvalue(bcx, dst, "assign_op"));
@ -2606,7 +2603,7 @@ enum ExprKind {
} }
fn expr_kind(tcx: &ty::ctxt, expr: &ast::Expr) -> ExprKind { fn expr_kind(tcx: &ty::ctxt, expr: &ast::Expr) -> ExprKind {
if tcx.tables.borrow().method_map.contains_key(&MethodCall::expr(expr.id)) { if tcx.is_method_call(expr.id) {
// Overloaded operations are generally calls, and hence they are // Overloaded operations are generally calls, and hence they are
// generated via DPS, but there are a few exceptions: // generated via DPS, but there are a few exceptions:
return match expr.node { return match expr.node {

View file

@ -516,8 +516,7 @@ fn visit_expr(rcx: &mut Rcx, expr: &ast::Expr) {
type_must_outlive(rcx, infer::ExprTypeIsNotInScope(expr_ty, expr.span), type_must_outlive(rcx, infer::ExprTypeIsNotInScope(expr_ty, expr.span),
expr_ty, ty::ReScope(CodeExtent::from_node_id(expr.id))); expr_ty, ty::ReScope(CodeExtent::from_node_id(expr.id)));
let method_call = MethodCall::expr(expr.id); let has_method_map = rcx.fcx.infcx().is_method_call(expr.id);
let has_method_map = rcx.fcx.inh.tables.borrow().method_map.contains_key(&method_call);
// Check any autoderefs or autorefs that appear. // Check any autoderefs or autorefs that appear.
let adjustment = rcx.fcx.inh.tables.borrow().adjustments.get(&expr.id).map(|a| a.clone()); let adjustment = rcx.fcx.inh.tables.borrow().adjustments.get(&expr.id).map(|a| a.clone());