librustc: Remove old-style operator overloading

This commit is contained in:
Patrick Walton 2013-03-08 16:13:01 -08:00
parent 1274d4a006
commit 7353568cd8
2 changed files with 34 additions and 14 deletions

View File

@ -105,17 +105,24 @@ trait `ToStr` imported, and I call `to_str()` on a value of type `T`,
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 @@ fn push_inherent_candidates(&self, self_ty: ty::t) {
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 */ }
}

View File

@ -89,7 +89,8 @@
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 @@ fn check_method_call(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 @@ fn lookup_op_method(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 @@ fn check_field(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));