From 93c2f5e0e43532a2288ed6dec378564264d1a77c Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 27 Jul 2012 19:32:42 -0700 Subject: rustc: Use coherence for operator overloading. The only use of the old-style impls is now placement new. --- src/libcore/core.rs | 3 ++- src/libcore/ops.rs | 50 +++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 43 insertions(+), 10 deletions(-) (limited to 'src/libcore') diff --git a/src/libcore/core.rs b/src/libcore/core.rs index fdf53524188..cd7252be9ec 100644 --- a/src/libcore/core.rs +++ b/src/libcore/core.rs @@ -31,7 +31,8 @@ import f32::num; import f64::num; import num::num; import ops::{const, copy, send, owned}; -import ops::{add, sub, mul, div, modulo, neg, bitops, index}; +import ops::{add, sub, mul, div, modulo, neg, bitand, bitor, bitxor, shl}; +import ops::{shr, index}; export path, option, some, none, unreachable; export extensions; diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index 61efe704974..2a05aeb72c2 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -1,64 +1,96 @@ // Core operators and kinds. +#[cfg(notest)] #[lang="const"] trait const { // Empty. } +#[cfg(notest)] #[lang="copy"] trait copy { // Empty. } +#[cfg(notest)] #[lang="send"] trait send { // Empty. } +#[cfg(notest)] #[lang="owned"] trait owned { // Empty. } +#[cfg(notest)] #[lang="add"] trait add { pure fn add(rhs: RHS) -> Result; } +#[cfg(notest)] #[lang="sub"] trait sub { pure fn sub(rhs: RHS) -> Result; } +#[cfg(notest)] #[lang="mul"] trait mul { pure fn mul(rhs: RHS) -> Result; } +#[cfg(notest)] #[lang="div"] trait div { pure fn div(rhs: RHS) -> Result; } +#[cfg(notest)] #[lang="modulo"] trait modulo { pure fn modulo(rhs: RHS) -> Result; } +#[cfg(notest)] #[lang="neg"] -trait neg { - pure fn neg(rhs: RHS) -> Result; +trait neg { + pure fn neg() -> Result; } -#[lang="bitops"] -trait bitops { - pure fn and(rhs: RHS) -> Result; - pure fn or(rhs: RHS) -> Result; - pure fn xor(rhs: RHS) -> Result; - pure fn shl(n: BitCount) -> Result; - pure fn shr(n: BitCount) -> Result; +#[cfg(notest)] +#[lang="bitand"] +trait bitand { + pure fn bitand(rhs: RHS) -> Result; } +#[cfg(notest)] +#[lang="bitor"] +trait bitor { + pure fn bitor(rhs: RHS) -> Result; +} + +#[cfg(notest)] +#[lang="bitxor"] +trait bitxor { + pure fn bitxor(rhs: RHS) -> Result; +} + +#[cfg(notest)] +#[lang="shl"] +trait shl { + pure fn shl(rhs: RHS) -> Result; +} + +#[cfg(notest)] +#[lang="shr"] +trait shr { + pure fn shr(rhs: RHS) -> Result; +} + +#[cfg(notest)] #[lang="index"] trait index { pure fn index(index: Index) -> Result; -- cgit 1.4.1-3-g733a5