Skip to content

Commit b85158e

Browse files
committed
librustc: Remove overloaded operator autoderef.
1 parent b1c6998 commit b85158e

File tree

4 files changed

+63
-29
lines changed

4 files changed

+63
-29
lines changed

src/librustc/middle/trans/foreign.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ pub fn trans_foreign_mod(ccx: @CrateContext,
312312
let lname = link_name(ccx, foreign_item);
313313
let llbasefn = base_fn(ccx, *lname, tys, cc);
314314
// Name the shim function
315-
let shim_name = lname + ~"__c_stack_shim";
315+
let shim_name = *lname + ~"__c_stack_shim";
316316
return build_shim_fn_(ccx, shim_name, llbasefn, tys, cc,
317317
build_args, build_ret);
318318
}

src/librustc/middle/typeck/check/method.rs

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -111,20 +111,26 @@ pub enum CheckTraitsFlag {
111111
CheckTraitsAndInherentMethods,
112112
}
113113

114-
pub fn lookup(
115-
fcx: @mut FnCtxt,
114+
#[deriving_eq]
115+
pub enum AutoderefReceiverFlag {
116+
AutoderefReceiver,
117+
DontAutoderefReceiver,
118+
}
116119

117-
// In a call `a.b::<X, Y, ...>(...)`:
118-
expr: @ast::expr, // The expression `a.b`.
119-
self_expr: @ast::expr, // The expression `a`.
120-
callee_id: node_id, // Where to store the type of `a.b`
121-
m_name: ast::ident, // The ident `b`.
122-
self_ty: ty::t, // The type of `a`.
123-
supplied_tps: &[ty::t], // The list of types X, Y, ... .
124-
deref_args: check::DerefArgs, // Whether we autopointer first.
125-
check_traits: CheckTraitsFlag) // Whether we check traits only.
126-
-> Option<method_map_entry>
127-
{
120+
pub fn lookup(
121+
fcx: @mut FnCtxt,
122+
123+
// In a call `a.b::<X, Y, ...>(...)`:
124+
expr: @ast::expr, // The expression `a.b`.
125+
self_expr: @ast::expr, // The expression `a`.
126+
callee_id: node_id, // Where to store `a.b`'s type
127+
m_name: ast::ident, // The ident `b`.
128+
self_ty: ty::t, // The type of `a`.
129+
supplied_tps: &[ty::t], // The list of types X, Y, ... .
130+
deref_args: check::DerefArgs, // Whether we autopointer first.
131+
check_traits: CheckTraitsFlag, // Whether we check traits only.
132+
autoderef_receiver: AutoderefReceiverFlag)
133+
-> Option<method_map_entry> {
128134
let lcx = LookupContext {
129135
fcx: fcx,
130136
expr: expr,
@@ -137,6 +143,7 @@ pub fn lookup(
137143
extension_candidates: @mut ~[],
138144
deref_args: deref_args,
139145
check_traits: check_traits,
146+
autoderef_receiver: autoderef_receiver,
140147
};
141148
let mme = lcx.do_lookup(self_ty);
142149
debug!("method lookup for %s yielded %?",
@@ -156,6 +163,7 @@ pub struct LookupContext {
156163
extension_candidates: @mut ~[Candidate],
157164
deref_args: check::DerefArgs,
158165
check_traits: CheckTraitsFlag,
166+
autoderef_receiver: AutoderefReceiverFlag,
159167
}
160168

161169
/**
@@ -232,6 +240,12 @@ pub impl LookupContext/&self {
232240
}
233241
}
234242

243+
// Don't autoderef if we aren't supposed to.
244+
if self.autoderef_receiver == DontAutoderefReceiver {
245+
break;
246+
}
247+
248+
// Otherwise, perform autoderef.
235249
match self.deref(self_ty, &mut enum_dids) {
236250
None => { break; }
237251
Some(ty) => {

src/librustc/middle/typeck/check/mod.rs

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,11 @@ use middle::typeck::astconv::{AstConv, ast_path_to_ty};
8989
use middle::typeck::astconv::{ast_region_to_region, ast_ty_to_ty};
9090
use middle::typeck::astconv;
9191
use middle::typeck::check::_match::pat_ctxt;
92+
use middle::typeck::check::method::{AutoderefReceiver};
93+
use middle::typeck::check::method::{AutoderefReceiverFlag};
9294
use middle::typeck::check::method::{CheckTraitsAndInherentMethods};
93-
use middle::typeck::check::method::{CheckTraitsOnly, TransformTypeNormally};
95+
use middle::typeck::check::method::{CheckTraitsOnly, DontAutoderefReceiver};
96+
use middle::typeck::check::method::{TransformTypeNormally};
9497
use middle::typeck::check::regionmanip::replace_bound_regions_in_fn_sig;
9598
use middle::typeck::check::vtable::{LocationInfo, VtableContext};
9699
use middle::typeck::CrateCtxt;
@@ -1373,7 +1376,8 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
13731376
expr_t,
13741377
tps,
13751378
DontDerefArgs,
1376-
CheckTraitsAndInherentMethods) {
1379+
CheckTraitsAndInherentMethods,
1380+
AutoderefReceiver) {
13771381
Some(ref entry) => {
13781382
let method_map = fcx.ccx.method_map;
13791383
method_map.insert(expr.id, (*entry));
@@ -1453,7 +1457,8 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
14531457
self_t: ty::t,
14541458
opname: ast::ident,
14551459
+args: ~[@ast::expr],
1456-
+deref_args: DerefArgs)
1460+
+deref_args: DerefArgs,
1461+
+autoderef_receiver: AutoderefReceiverFlag)
14571462
-> Option<(ty::t, bool)> {
14581463
match method::lookup(fcx,
14591464
op_ex,
@@ -1463,7 +1468,8 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
14631468
self_t,
14641469
~[],
14651470
deref_args,
1466-
CheckTraitsOnly) {
1471+
CheckTraitsOnly,
1472+
autoderef_receiver) {
14671473
Some(ref origin) => {
14681474
let method_ty = fcx.node_ty(op_ex.callee_id);
14691475
let method_map = fcx.ccx.method_map;
@@ -1548,9 +1554,14 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
15481554
let tcx = fcx.ccx.tcx;
15491555
match ast_util::binop_to_method_name(op) {
15501556
Some(ref name) => {
1551-
match lookup_op_method(fcx, ex, lhs_expr, lhs_resolved_t,
1557+
match lookup_op_method(fcx,
1558+
ex,
1559+
lhs_expr,
1560+
lhs_resolved_t,
15521561
fcx.tcx().sess.ident_of(copy *name),
1553-
~[rhs], DoDerefArgs) {
1562+
~[rhs],
1563+
DoDerefArgs,
1564+
DontAutoderefReceiver) {
15541565
Some(pair) => return pair,
15551566
_ => ()
15561567
}
@@ -1588,11 +1599,14 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
15881599
rhs_expr: @ast::expr,
15891600
rhs_t: ty::t)
15901601
-> ty::t {
1591-
match lookup_op_method(
1592-
fcx, ex, rhs_expr, rhs_t,
1593-
fcx.tcx().sess.ident_of(/*bad*/ copy mname), ~[],
1594-
DontDerefArgs)
1595-
{
1602+
match lookup_op_method(fcx,
1603+
ex,
1604+
rhs_expr,
1605+
rhs_t,
1606+
fcx.tcx().sess.ident_of(/*bad*/ copy mname),
1607+
~[],
1608+
DontDerefArgs,
1609+
DontAutoderefReceiver) {
15961610
Some((ret_ty, _)) => ret_ty,
15971611
_ => {
15981612
fcx.type_error_message(ex.span, |actual| {
@@ -1740,7 +1754,8 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
17401754
expr_t,
17411755
tps,
17421756
DontDerefArgs,
1743-
CheckTraitsAndInherentMethods) {
1757+
CheckTraitsAndInherentMethods,
1758+
AutoderefReceiver) {
17441759
Some(ref entry) => {
17451760
let method_map = fcx.ccx.method_map;
17461761
method_map.insert(expr.id, (*entry));
@@ -2569,9 +2584,14 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
25692584
None => {
25702585
let resolved = structurally_resolved_type(fcx, expr.span,
25712586
raw_base_t);
2572-
match lookup_op_method(fcx, expr, base, resolved,
2587+
match lookup_op_method(fcx,
2588+
expr,
2589+
base,
2590+
resolved,
25732591
tcx.sess.ident_of(~"index"),
2574-
~[idx], DontDerefArgs) {
2592+
~[idx],
2593+
DontDerefArgs,
2594+
AutoderefReceiver) {
25752595
Some((ret_ty, _)) => fcx.write_ty(id, ret_ty),
25762596
_ => {
25772597
fcx.type_error_message(expr.span, |actual|

src/libsyntax/parse/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3407,7 +3407,7 @@ pub impl Parser {
34073407
let prefix = Path(self.sess.cm.span_to_filename(*self.span));
34083408
let prefix = prefix.dir_path();
34093409
let mod_path = Path(".").push_many(*self.mod_path_stack);
3410-
let default_path = self.sess.interner.get(id) + ~".rs";
3410+
let default_path = *self.sess.interner.get(id) + ~".rs";
34113411
let file_path = match ::attr::first_attr_value_str_by_name(
34123412
outer_attrs, ~"path") {
34133413
Some(d) => {

0 commit comments

Comments
 (0)