Skip to content

Commit 7e81914

Browse files
committed
librustc: Remove old-style operator overloading
1 parent 11554ef commit 7e81914

File tree

2 files changed

+34
-14
lines changed

2 files changed

+34
-14
lines changed

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

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,24 @@ use syntax::ast::{m_const, m_mutbl, m_imm};
105105
use syntax::ast;
106106
use syntax::ast_map;
107107

108+
#[deriving_eq]
109+
pub enum CheckTraitsFlag {
110+
CheckTraitsOnly,
111+
CheckTraitsAndInherentMethods,
112+
}
113+
108114
pub fn lookup(
109115
fcx: @mut FnCtxt,
110116

111117
// In a call `a.b::<X, Y, ...>(...)`:
112-
expr: @ast::expr, // The expression `a.b`.
113-
self_expr: @ast::expr, // The expression `a`.
114-
callee_id: node_id, // Where to store the type of `a.b`
115-
m_name: ast::ident, // The ident `b`.
116-
self_ty: ty::t, // The type of `a`.
117-
supplied_tps: &[ty::t], // The list of types X, Y, ... .
118-
deref_args: check::DerefArgs) // Whether we autopointer first.
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.
119126
-> Option<method_map_entry>
120127
{
121128
let lcx = LookupContext {
@@ -129,6 +136,7 @@ pub fn lookup(
129136
inherent_candidates: @mut ~[],
130137
extension_candidates: @mut ~[],
131138
deref_args: deref_args,
139+
check_traits: check_traits,
132140
};
133141
let mme = lcx.do_lookup(self_ty);
134142
debug!("method lookup for %s yielded %?",
@@ -147,6 +155,7 @@ pub struct LookupContext {
147155
inherent_candidates: @mut ~[Candidate],
148156
extension_candidates: @mut ~[Candidate],
149157
deref_args: check::DerefArgs,
158+
check_traits: CheckTraitsFlag,
150159
}
151160

152161
/**
@@ -298,7 +307,9 @@ pub impl LookupContext/&self {
298307
self_ty, self_did, &substs);
299308
}
300309
ty_enum(did, _) | ty_struct(did, _) => {
301-
self.push_inherent_impl_candidates_for_type(did);
310+
if self.check_traits == CheckTraitsAndInherentMethods {
311+
self.push_inherent_impl_candidates_for_type(did);
312+
}
302313
}
303314
_ => { /* No inherent methods in these types */ }
304315
}

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ 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::TransformTypeNormally;
92+
use middle::typeck::check::method::{CheckTraitsAndInherentMethods};
93+
use middle::typeck::check::method::{CheckTraitsOnly, TransformTypeNormally};
9394
use middle::typeck::check::regionmanip::replace_bound_regions_in_fn_sig;
9495
use middle::typeck::check::vtable::{LocationInfo, VtableContext};
9596
use middle::typeck::CrateCtxt;
@@ -1365,7 +1366,8 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
13651366
method_name,
13661367
expr_t,
13671368
tps,
1368-
DontDerefArgs) {
1369+
DontDerefArgs,
1370+
CheckTraitsAndInherentMethods) {
13691371
Some(ref entry) => {
13701372
let method_map = fcx.ccx.method_map;
13711373
method_map.insert(expr.id, (*entry));
@@ -1447,9 +1449,15 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
14471449
+args: ~[@ast::expr],
14481450
+deref_args: DerefArgs)
14491451
-> Option<(ty::t, bool)> {
1450-
match method::lookup(fcx, op_ex, self_ex,
1451-
op_ex.callee_id, opname, self_t, ~[],
1452-
deref_args) {
1452+
match method::lookup(fcx,
1453+
op_ex,
1454+
self_ex,
1455+
op_ex.callee_id,
1456+
opname,
1457+
self_t,
1458+
~[],
1459+
deref_args,
1460+
CheckTraitsOnly) {
14531461
Some(ref origin) => {
14541462
let method_ty = fcx.node_ty(op_ex.callee_id);
14551463
let method_map = fcx.ccx.method_map;
@@ -1721,7 +1729,8 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
17211729
field,
17221730
expr_t,
17231731
tps,
1724-
DontDerefArgs) {
1732+
DontDerefArgs,
1733+
CheckTraitsAndInherentMethods) {
17251734
Some(ref entry) => {
17261735
let method_map = fcx.ccx.method_map;
17271736
method_map.insert(expr.id, (*entry));

0 commit comments

Comments
 (0)