about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2013-03-08 16:13:01 -0800
committerPatrick Walton <pcwalton@mimiga.net>2013-03-11 09:36:00 -0700
commit7353568cd8d079fd4d9f928bc49a228276e86d19 (patch)
tree210aa5c275f2faf3e8995af7e1370487dd08f79a
parent1274d4a0063fbb0ae5feaa277caf08c3230b46a9 (diff)
downloadrust-7353568cd8d079fd4d9f928bc49a228276e86d19.tar.gz
rust-7353568cd8d079fd4d9f928bc49a228276e86d19.zip
librustc: Remove old-style operator overloading
-rw-r--r--src/librustc/middle/typeck/check/method.rs27
-rw-r--r--src/librustc/middle/typeck/check/mod.rs21
2 files changed, 34 insertions, 14 deletions
diff --git a/src/librustc/middle/typeck/check/method.rs b/src/librustc/middle/typeck/check/method.rs
index 3395d9b4451..d6060c1ae31 100644
--- a/src/librustc/middle/typeck/check/method.rs
+++ b/src/librustc/middle/typeck/check/method.rs
@@ -105,17 +105,24 @@ use syntax::ast::{m_const, m_mutbl, m_imm};
 use syntax::ast;
 use syntax::ast_map;
 
+#[deriving_eq]
+pub enum CheckTraitsFlag {
+    CheckTraitsOnly,
+    CheckTraitsAndInherentMethods,
+}
+
 pub fn lookup(
     fcx: @mut FnCtxt,
 
     // In a call `a.b::<X, Y, ...>(...)`:
-    expr: @ast::expr,        // The expression `a.b`.
-    self_expr: @ast::expr,   // The expression `a`.
-    callee_id: node_id, // Where to store the type of `a.b`
-    m_name: ast::ident,      // The ident `b`.
-    self_ty: ty::t,          // The type of `a`.
-    supplied_tps: &[ty::t],  // The list of types X, Y, ... .
-    deref_args: check::DerefArgs)   // Whether we autopointer first.
+    expr: @ast::expr,                   // The expression `a.b`.
+    self_expr: @ast::expr,              // The expression `a`.
+    callee_id: node_id,                 // Where to store the type of `a.b`
+    m_name: ast::ident,                 // The ident `b`.
+    self_ty: ty::t,                     // The type of `a`.
+    supplied_tps: &[ty::t],             // The list of types X, Y, ... .
+    deref_args: check::DerefArgs,       // Whether we autopointer first.
+    check_traits: CheckTraitsFlag)      // Whether we check traits only.
     -> Option<method_map_entry>
 {
     let lcx = LookupContext {
@@ -129,6 +136,7 @@ pub fn lookup(
         inherent_candidates: @mut ~[],
         extension_candidates: @mut ~[],
         deref_args: deref_args,
+        check_traits: check_traits,
     };
     let mme = lcx.do_lookup(self_ty);
     debug!("method lookup for %s yielded %?",
@@ -147,6 +155,7 @@ pub struct LookupContext {
     inherent_candidates: @mut ~[Candidate],
     extension_candidates: @mut ~[Candidate],
     deref_args: check::DerefArgs,
+    check_traits: CheckTraitsFlag,
 }
 
 /**
@@ -299,7 +308,9 @@ pub impl LookupContext/&self {
                         self_ty, self_did, &substs);
                 }
                 ty_enum(did, _) | ty_struct(did, _) => {
-                    self.push_inherent_impl_candidates_for_type(did);
+                    if self.check_traits == CheckTraitsAndInherentMethods {
+                        self.push_inherent_impl_candidates_for_type(did);
+                    }
                 }
                 _ => { /* No inherent methods in these types */ }
             }
diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs
index f3804934186..6617fa3b27c 100644
--- a/src/librustc/middle/typeck/check/mod.rs
+++ b/src/librustc/middle/typeck/check/mod.rs
@@ -89,7 +89,8 @@ use middle::typeck::astconv::{AstConv, ast_path_to_ty};
 use middle::typeck::astconv::{ast_region_to_region, ast_ty_to_ty};
 use middle::typeck::astconv;
 use middle::typeck::check::_match::pat_ctxt;
-use middle::typeck::check::method::TransformTypeNormally;
+use middle::typeck::check::method::{CheckTraitsAndInherentMethods};
+use middle::typeck::check::method::{CheckTraitsOnly, TransformTypeNormally};
 use middle::typeck::check::regionmanip::replace_bound_regions_in_fn_sig;
 use middle::typeck::check::vtable::{LocationInfo, VtableContext};
 use middle::typeck::CrateCtxt;
@@ -1371,7 +1372,8 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
                              method_name,
                              expr_t,
                              tps,
-                             DontDerefArgs) {
+                             DontDerefArgs,
+                             CheckTraitsAndInherentMethods) {
             Some(ref entry) => {
                 let method_map = fcx.ccx.method_map;
                 method_map.insert(expr.id, (*entry));
@@ -1453,9 +1455,15 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
                         +args: ~[@ast::expr],
                         +deref_args: DerefArgs)
                      -> Option<(ty::t, bool)> {
-        match method::lookup(fcx, op_ex, self_ex,
-                             op_ex.callee_id, opname, self_t, ~[],
-                             deref_args) {
+        match method::lookup(fcx,
+                             op_ex,
+                             self_ex,
+                             op_ex.callee_id,
+                             opname,
+                             self_t,
+                             ~[],
+                             deref_args,
+                             CheckTraitsOnly) {
           Some(ref origin) => {
               let method_ty = fcx.node_ty(op_ex.callee_id);
               let method_map = fcx.ccx.method_map;
@@ -1732,7 +1740,8 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
                              field,
                              expr_t,
                              tps,
-                             DontDerefArgs) {
+                             DontDerefArgs,
+                             CheckTraitsAndInherentMethods) {
             Some(ref entry) => {
                 let method_map = fcx.ccx.method_map;
                 method_map.insert(expr.id, (*entry));