diff --git a/doc/rust.md b/doc/rust.md
index e9c88fc3412..b1eb5521b39 100644
--- a/doc/rust.md
+++ b/doc/rust.md
@@ -1467,10 +1467,10 @@ A complete list of the built-in language items follows:
: Elements can be subtracted.
`mul`
: Elements can be multiplied.
-`div`
- : Elements can be divided.
-`mod`
- : Elements have a modulo operation.
+`quot`
+ : Elements have a quotient operation.
+`rem`
+ : Elements have a remainder operation.
`neg`
: Elements can be negated arithmetically.
`not`
@@ -1856,11 +1856,11 @@ The default meaning of the operators on standard types is given here.
: Multiplication.
Calls the `mul` method on the `core::ops::Mul` trait.
`/`
- : Division.
- Calls the `div` method on the `core::ops::Div` trait.
+ : Quotient.
+ Calls the `quot` method on the `core::ops::Quot` trait.
`%`
- : Modulo (a.k.a. "remainder").
- Calls the `modulo` method on the `core::ops::Modulo` trait.
+ : Remainder.
+ Calls the `rem` method on the `core::ops::Rem` trait.
#### Bitwise operators
diff --git a/doc/tutorial.md b/doc/tutorial.md
index 56629b93b1a..c10bc8a294c 100644
--- a/doc/tutorial.md
+++ b/doc/tutorial.md
@@ -362,7 +362,7 @@ The nil type, written `()`, has a single value, also written `()`.
## Operators
Rust's set of operators contains very few surprises. Arithmetic is done with
-`*`, `/`, `%`, `+`, and `-` (multiply, divide, take remainder, add, and subtract). `-` is
+`*`, `/`, `%`, `+`, and `-` (multiply, quotient, remainder, add, and subtract). `-` is
also a unary prefix operator that negates numbers. As in C, the bitwise operators
`>>`, `<<`, `&`, `|`, and `^` are also supported.
diff --git a/src/etc/kate/rust.xml b/src/etc/kate/rust.xml
index 59f8c164588..6a751bd1c85 100644
--- a/src/etc/kate/rust.xml
+++ b/src/etc/kate/rust.xml
@@ -57,8 +57,8 @@
- Add
- Sub
- Mul
- - Div
- - Modulo
+ - Quot
+ - Rem
- Neg
- BitAnd
- BitOr
diff --git a/src/etc/vim/syntax/rust.vim b/src/etc/vim/syntax/rust.vim
index 3e6c11c6238..eab3627ae16 100644
--- a/src/etc/vim/syntax/rust.vim
+++ b/src/etc/vim/syntax/rust.vim
@@ -46,7 +46,7 @@ syn keyword rustType off_t dev_t ino_t pid_t mode_t ssize_t
syn keyword rustTrait Const Copy Send Owned " inherent traits
syn keyword rustTrait Eq Ord Num Ptr
-syn keyword rustTrait Drop Add Sub Mul Div Modulo Neg BitAnd BitOr
+syn keyword rustTrait Drop Add Sub Mul Quot Rem Neg BitAnd BitOr
syn keyword rustTrait BitXor Shl Shr Index
syn keyword rustSelf self
diff --git a/src/libcore/core.rc b/src/libcore/core.rc
index 81190ea8fc6..fd8813d0c4a 100644
--- a/src/libcore/core.rc
+++ b/src/libcore/core.rc
@@ -75,7 +75,12 @@ they contained the following prologue:
pub use kinds::{Const, Copy, Owned, Durable};
pub use ops::{Drop};
+#[cfg(stage0)]
pub use ops::{Add, Sub, Mul, Div, Modulo, Neg, Not};
+#[cfg(stage1)]
+#[cfg(stage2)]
+#[cfg(stage3)]
+pub use ops::{Add, Sub, Mul, Quot, Rem, Neg, Not};
pub use ops::{BitAnd, BitOr, BitXor};
pub use ops::{Shl, Shr, Index};
diff --git a/src/libcore/num/f32.rs b/src/libcore/num/f32.rs
index 6233f8c2a61..2e7dc98e3c5 100644
--- a/src/libcore/num/f32.rs
+++ b/src/libcore/num/f32.rs
@@ -16,8 +16,13 @@ use option::Option;
use from_str;
use to_str;
-#[cfg(notest)] use cmp;
-#[cfg(notest)] use ops;
+#[cfg(notest)] use cmp::{Eq, Ord};
+#[cfg(stage0,notest)]
+use ops::{Add, Sub, Mul, Div, Modulo, Neg};
+#[cfg(stage1,notest)]
+#[cfg(stage2,notest)]
+#[cfg(stage3,notest)]
+use ops::{Add, Sub, Mul, Quot, Rem, Neg};
pub use cmath::c_float_targ_consts::*;
@@ -131,7 +136,7 @@ pub fn sub(x: f32, y: f32) -> f32 { return x - y; }
pub fn mul(x: f32, y: f32) -> f32 { return x * y; }
#[inline(always)]
-pub fn div(x: f32, y: f32) -> f32 { return x / y; }
+pub fn quot(x: f32, y: f32) -> f32 { return x / y; }
#[inline(always)]
pub fn rem(x: f32, y: f32) -> f32 { return x % y; }
@@ -265,7 +270,7 @@ pub fn logarithm(n: f32, b: f32) -> f32 {
}
#[cfg(notest)]
-impl cmp::Eq for f32 {
+impl Eq for f32 {
#[inline(always)]
fn eq(&self, other: &f32) -> bool { (*self) == (*other) }
#[inline(always)]
@@ -273,7 +278,7 @@ impl cmp::Eq for f32 {
}
#[cfg(notest)]
-impl cmp::Ord for f32 {
+impl Ord for f32 {
#[inline(always)]
fn lt(&self, other: &f32) -> bool { (*self) < (*other) }
#[inline(always)]
@@ -295,33 +300,41 @@ impl num::One for f32 {
}
#[cfg(notest)]
-impl ops::Add for f32 {
- #[inline(always)]
+impl Add for f32 {
fn add(&self, other: &f32) -> f32 { *self + *other }
}
#[cfg(notest)]
-impl ops::Sub for f32 {
- #[inline(always)]
+impl Sub for f32 {
fn sub(&self, other: &f32) -> f32 { *self - *other }
}
#[cfg(notest)]
-impl ops::Mul for f32 {
- #[inline(always)]
+impl Mul for f32 {
fn mul(&self, other: &f32) -> f32 { *self * *other }
}
-#[cfg(notest)]
-impl ops::Div for f32 {
- #[inline(always)]
+#[cfg(stage0,notest)]
+impl Div for f32 {
fn div(&self, other: &f32) -> f32 { *self / *other }
}
-#[cfg(notest)]
-impl ops::Modulo for f32 {
+#[cfg(stage1,notest)]
+#[cfg(stage2,notest)]
+#[cfg(stage3,notest)]
+impl Quot for f32 {
#[inline(always)]
+ fn quot(&self, other: &f32) -> f32 { *self / *other }
+}
+#[cfg(stage0,notest)]
+impl Modulo for f32 {
fn modulo(&self, other: &f32) -> f32 { *self % *other }
}
-#[cfg(notest)]
-impl ops::Neg for f32 {
+#[cfg(stage1,notest)]
+#[cfg(stage2,notest)]
+#[cfg(stage3,notest)]
+impl Rem for f32 {
#[inline(always)]
+ fn rem(&self, other: &f32) -> f32 { *self % *other }
+}
+#[cfg(notest)]
+impl Neg for f32 {
fn neg(&self) -> f32 { -*self }
}
diff --git a/src/libcore/num/f64.rs b/src/libcore/num/f64.rs
index 7f32893f5bf..4762c395a25 100644
--- a/src/libcore/num/f64.rs
+++ b/src/libcore/num/f64.rs
@@ -16,8 +16,13 @@ use option::Option;
use to_str;
use from_str;
-#[cfg(notest)] use cmp;
-#[cfg(notest)] use ops;
+#[cfg(notest)] use cmp::{Eq, Ord};
+#[cfg(stage0,notest)]
+use ops::{Add, Sub, Mul, Div, Modulo, Neg};
+#[cfg(stage1,notest)]
+#[cfg(stage2,notest)]
+#[cfg(stage3,notest)]
+use ops::{Add, Sub, Mul, Quot, Rem, Neg};
pub use cmath::c_double_targ_consts::*;
pub use cmp::{min, max};
@@ -155,7 +160,7 @@ pub fn sub(x: f64, y: f64) -> f64 { return x - y; }
pub fn mul(x: f64, y: f64) -> f64 { return x * y; }
#[inline(always)]
-pub fn div(x: f64, y: f64) -> f64 { return x / y; }
+pub fn quot(x: f64, y: f64) -> f64 { return x / y; }
#[inline(always)]
pub fn rem(x: f64, y: f64) -> f64 { return x % y; }
@@ -284,7 +289,7 @@ pub fn logarithm(n: f64, b: f64) -> f64 {
}
#[cfg(notest)]
-impl cmp::Eq for f64 {
+impl Eq for f64 {
#[inline(always)]
fn eq(&self, other: &f64) -> bool { (*self) == (*other) }
#[inline(always)]
@@ -292,7 +297,7 @@ impl cmp::Eq for f64 {
}
#[cfg(notest)]
-impl cmp::Ord for f64 {
+impl Ord for f64 {
#[inline(always)]
fn lt(&self, other: &f64) -> bool { (*self) < (*other) }
#[inline(always)]
@@ -314,33 +319,41 @@ impl num::One for f64 {
}
#[cfg(notest)]
-impl ops::Add for f64 {
- #[inline(always)]
+impl Add for f64 {
fn add(&self, other: &f64) -> f64 { *self + *other }
}
#[cfg(notest)]
-impl ops::Sub for f64 {
- #[inline(always)]
+impl Sub for f64 {
fn sub(&self, other: &f64) -> f64 { *self - *other }
}
#[cfg(notest)]
-impl ops::Mul for f64 {
- #[inline(always)]
+impl Mul for f64 {
fn mul(&self, other: &f64) -> f64 { *self * *other }
}
-#[cfg(notest)]
-impl ops::Div for f64 {
- #[inline(always)]
+#[cfg(stage0,notest)]
+impl Div for f64 {
fn div(&self, other: &f64) -> f64 { *self / *other }
}
-#[cfg(notest)]
-impl ops::Modulo for f64 {
+#[cfg(stage1,notest)]
+#[cfg(stage2,notest)]
+#[cfg(stage3,notest)]
+impl Quot for f64 {
#[inline(always)]
+ fn quot(&self, other: &f64) -> f64 { *self / *other }
+}
+#[cfg(stage0,notest)]
+impl Modulo for f64 {
fn modulo(&self, other: &f64) -> f64 { *self % *other }
}
-#[cfg(notest)]
-impl ops::Neg for f64 {
+#[cfg(stage1,notest)]
+#[cfg(stage2,notest)]
+#[cfg(stage3,notest)]
+impl Rem for f64 {
#[inline(always)]
+ fn rem(&self, other: &f64) -> f64 { *self % *other }
+}
+#[cfg(notest)]
+impl Neg for f64 {
fn neg(&self) -> f64 { -*self }
}
diff --git a/src/libcore/num/float.rs b/src/libcore/num/float.rs
index c9cda20640d..9cf14cf0f49 100644
--- a/src/libcore/num/float.rs
+++ b/src/libcore/num/float.rs
@@ -28,9 +28,14 @@ use to_str;
use from_str;
#[cfg(notest)] use cmp::{Eq, Ord};
-#[cfg(notest)] use ops;
+#[cfg(stage0,notest)]
+use ops::{Add, Sub, Mul, Div, Modulo, Neg};
+#[cfg(stage1,notest)]
+#[cfg(stage2,notest)]
+#[cfg(stage3,notest)]
+use ops::{Add, Sub, Mul, Quot, Rem, Neg};
-pub use f64::{add, sub, mul, div, rem, lt, le, eq, ne, ge, gt};
+pub use f64::{add, sub, mul, quot, rem, lt, le, eq, ne, ge, gt};
pub use f64::logarithm;
pub use f64::{acos, asin, atan2, cbrt, ceil, copysign, cosh, floor};
pub use f64::{erf, erfc, exp, expm1, exp2, abs_sub};
@@ -449,33 +454,41 @@ impl num::Round for float {
}
#[cfg(notest)]
-impl ops::Add for float {
- #[inline(always)]
+impl Add for float {
fn add(&self, other: &float) -> float { *self + *other }
}
#[cfg(notest)]
-impl ops::Sub for float {
- #[inline(always)]
+impl Sub for float {
fn sub(&self, other: &float) -> float { *self - *other }
}
#[cfg(notest)]
-impl ops::Mul for float {
- #[inline(always)]
+impl Mul for float {
fn mul(&self, other: &float) -> float { *self * *other }
}
-#[cfg(notest)]
-impl ops::Div for float {
- #[inline(always)]
+#[cfg(stage0,notest)]
+impl Div for float {
fn div(&self, other: &float) -> float { *self / *other }
}
-#[cfg(notest)]
-impl ops::Modulo for float {
+#[cfg(stage1,notest)]
+#[cfg(stage2,notest)]
+#[cfg(stage3,notest)]
+impl Quot for float {
#[inline(always)]
+ fn quot(&self, other: &float) -> float { *self / *other }
+}
+#[cfg(stage0,notest)]
+impl Modulo for float {
fn modulo(&self, other: &float) -> float { *self % *other }
}
-#[cfg(notest)]
-impl ops::Neg for float {
+#[cfg(stage1,notest)]
+#[cfg(stage2,notest)]
+#[cfg(stage3,notest)]
+impl Rem for float {
#[inline(always)]
+ fn rem(&self, other: &float) -> float { *self % *other }
+}
+#[cfg(notest)]
+impl Neg for float {
fn neg(&self) -> float { -*self }
}
diff --git a/src/libcore/num/int-template.rs b/src/libcore/num/int-template.rs
index e170d85cc71..8f448994c98 100644
--- a/src/libcore/num/int-template.rs
+++ b/src/libcore/num/int-template.rs
@@ -17,8 +17,6 @@ use num::strconv;
use num;
use prelude::*;
-#[cfg(notest)] use cmp::{Eq, Ord};
-
pub use cmp::{min, max};
pub static bits : uint = inst::bits;
@@ -34,7 +32,7 @@ pub fn sub(x: T, y: T) -> T { x - y }
#[inline(always)]
pub fn mul(x: T, y: T) -> T { x * y }
#[inline(always)]
-pub fn div(x: T, y: T) -> T { x / y }
+pub fn quot(x: T, y: T) -> T { x / y }
/**
* Returns the remainder of y / x.
@@ -176,63 +174,71 @@ impl num::One for T {
}
#[cfg(notest)]
-impl ops::Add for T {
- #[inline(always)]
+impl Add for T {
fn add(&self, other: &T) -> T { *self + *other }
}
#[cfg(notest)]
-impl ops::Sub for T {
- #[inline(always)]
+impl Sub for T {
fn sub(&self, other: &T) -> T { *self - *other }
}
#[cfg(notest)]
-impl ops::Mul for T {
- #[inline(always)]
+impl Mul for T {
fn mul(&self, other: &T) -> T { *self * *other }
}
-#[cfg(notest)]
-impl ops::Div for T {
- #[inline(always)]
+#[cfg(stage0,notest)]
+impl Div for T {
fn div(&self, other: &T) -> T { *self / *other }
}
-#[cfg(notest)]
-impl ops::Modulo for T {
+#[cfg(stage1,notest)]
+#[cfg(stage2,notest)]
+#[cfg(stage3,notest)]
+impl Quot for T {
#[inline(always)]
+ fn quot(&self, other: &T) -> T { *self / *other }
+}
+#[cfg(stage0,notest)]
+impl Modulo for T {
fn modulo(&self, other: &T) -> T { *self % *other }
}
-#[cfg(notest)]
-impl ops::Neg for T {
+#[cfg(stage1,notest)]
+#[cfg(stage2,notest)]
+#[cfg(stage3,notest)]
+impl Rem for T {
#[inline(always)]
+ fn rem(&self, other: &T) -> T { *self % *other }
+}
+#[cfg(notest)]
+impl Neg for T {
fn neg(&self) -> T { -*self }
}
#[cfg(notest)]
-impl ops::BitOr for T {
+impl BitOr for T {
#[inline(always)]
fn bitor(&self, other: &T) -> T { *self | *other }
}
#[cfg(notest)]
-impl ops::BitAnd for T {
+impl BitAnd for T {
#[inline(always)]
fn bitand(&self, other: &T) -> T { *self & *other }
}
#[cfg(notest)]
-impl ops::BitXor for T {
+impl BitXor for T {
#[inline(always)]
fn bitxor(&self, other: &T) -> T { *self ^ *other }
}
#[cfg(notest)]
-impl ops::Shl for T {
+impl Shl for T {
#[inline(always)]
fn shl(&self, other: &T) -> T { *self << *other }
}
#[cfg(notest)]
-impl ops::Shr for T {
+impl Shr for T {
#[inline(always)]
fn shr(&self, other: &T) -> T { *self >> *other }
}
#[cfg(notest)]
-impl ops::Not for T {
+impl Not for T {
#[inline(always)]
fn not(&self) -> T { !*self }
}
diff --git a/src/libcore/num/num.rs b/src/libcore/num/num.rs
index 58342144752..a0ff510cde7 100644
--- a/src/libcore/num/num.rs
+++ b/src/libcore/num/num.rs
@@ -10,7 +10,16 @@
//! An interface for numeric types
use cmp::{Eq, Ord};
-use ops::{Neg, Add, Sub, Mul, Div, Modulo};
+#[cfg(stage0)]
+use ops::{Add, Sub, Mul, Neg};
+#[cfg(stage0)]
+use Quot = ops::Div;
+#[cfg(stage0)]
+use Rem = ops::Modulo;
+#[cfg(stage1)]
+#[cfg(stage2)]
+#[cfg(stage3)]
+use ops::{Add, Sub, Mul, Quot, Rem, Neg};
use option::Option;
use kinds::Copy;
@@ -21,8 +30,8 @@ pub trait Num: Eq + Zero + One
+ Add
+ Sub
+ Mul
- + Div
- + Modulo {}
+ + Quot
+ + Rem {}
impl Num for u8 {}
impl Num for u16 {}
@@ -174,7 +183,7 @@ pub trait FromStrRadix {
* - If code written to use this function doesn't care about it, it's
* probably assuming that `x^0` always equals `1`.
*/
-pub fn pow_with_uint+Mul>(
+pub fn pow_with_uint+Mul>(
radix: uint, pow: uint) -> T {
let _0: T = Zero::zero();
let _1: T = One::one();
@@ -194,7 +203,7 @@ pub fn pow_with_uint+Mul>(
total
}
-#[cfg(test)]
+#[cfg(stage0,test)]
fn test_num(ten: T, two: T) {
assert_eq!(ten.add(&two), cast(12));
assert_eq!(ten.sub(&two), cast(8));
@@ -208,6 +217,22 @@ fn test_num(ten: T, two: T) {
assert_eq!(ten.div(&two), ten / two);
assert_eq!(ten.modulo(&two), ten % two);
}
+#[cfg(stage1,test)]
+#[cfg(stage2,test)]
+#[cfg(stage3,test)]
+fn test_num(ten: T, two: T) {
+ assert_eq!(ten.add(&two), cast(12));
+ assert_eq!(ten.sub(&two), cast(8));
+ assert_eq!(ten.mul(&two), cast(20));
+ assert_eq!(ten.quot(&two), cast(5));
+ assert_eq!(ten.rem(&two), cast(0));
+
+ assert_eq!(ten.add(&two), ten + two);
+ assert_eq!(ten.sub(&two), ten - two);
+ assert_eq!(ten.mul(&two), ten * two);
+ assert_eq!(ten.quot(&two), ten / two);
+ assert_eq!(ten.rem(&two), ten % two);
+}
#[test] fn test_u8_num() { test_num(10u8, 2u8) }
#[test] fn test_u16_num() { test_num(10u16, 2u16) }
diff --git a/src/libcore/num/strconv.rs b/src/libcore/num/strconv.rs
index de699a3756b..4a45a1d9702 100644
--- a/src/libcore/num/strconv.rs
+++ b/src/libcore/num/strconv.rs
@@ -9,7 +9,16 @@
// except according to those terms.
use core::cmp::{Ord, Eq};
-use ops::{Add, Div, Modulo, Mul, Neg, Sub};
+#[cfg(stage0)]
+use ops::{Add, Sub, Mul, Neg};
+#[cfg(stage0)]
+use Quot = ops::Div;
+#[cfg(stage0)]
+use Rem = ops::Modulo;
+#[cfg(stage1)]
+#[cfg(stage2)]
+#[cfg(stage3)]
+use ops::{Add, Sub, Mul, Quot, Rem, Neg};
use option::{None, Option, Some};
use char;
use str;
@@ -58,7 +67,7 @@ fn is_neg_inf(num: &T) -> bool {
}
#[inline(always)]
-fn is_neg_zero>(num: &T) -> bool {
+fn is_neg_zero>(num: &T) -> bool {
let _0: T = Zero::zero();
let _1: T = One::one();
@@ -171,7 +180,7 @@ static nan_buf: [u8, ..3] = ['N' as u8, 'a' as u8, 'N' as u8];
* - Fails if `radix` < 2 or `radix` > 36.
*/
pub fn to_str_bytes_common+Neg+Modulo+Mul>(
+ Quot+Neg+Rem+Mul>(
num: &T, radix: uint, negative_zero: bool,
sign: SignFormat, digits: SignificantDigits) -> (~[u8], bool) {
if (radix as int) < 2 {
@@ -379,7 +388,7 @@ pub fn to_str_bytes_common+Neg+Modulo+Mul>(
+ Quot+Neg+Rem+Mul>(
num: &T, radix: uint, negative_zero: bool,
sign: SignFormat, digits: SignificantDigits) -> (~str, bool) {
let (bytes, special) = to_str_bytes_common(num, radix,
@@ -432,7 +441,7 @@ priv static DIGIT_E_RADIX: uint = ('e' as uint) - ('a' as uint) + 11u;
* - Fails if `radix` > 18 and `special == true` due to conflict
* between digit and lowest first character in `inf` and `NaN`, the `'i'`.
*/
-pub fn from_str_bytes_common+
+pub fn from_str_bytes_common+
Mul+Sub+Neg+Add+
NumStrConv>(
buf: &[u8], radix: uint, negative: bool, fractional: bool,
@@ -629,7 +638,7 @@ pub fn from_str_bytes_common+
* `from_str_bytes_common()`, for details see there.
*/
#[inline(always)]
-pub fn from_str_common+Mul+
+pub fn from_str_common+Mul+
Sub+Neg+Add+NumStrConv>(
buf: &str, radix: uint, negative: bool, fractional: bool,
special: bool, exponent: ExponentFormat, empty_zero: bool,
diff --git a/src/libcore/num/uint-template.rs b/src/libcore/num/uint-template.rs
index 0fb6ea614d8..6f3f402f92d 100644
--- a/src/libcore/num/uint-template.rs
+++ b/src/libcore/num/uint-template.rs
@@ -19,8 +19,6 @@ use num;
use option::Option;
use prelude::*;
-#[cfg(notest)] use cmp::{Eq, Ord};
-
pub use cmp::{min, max};
pub static bits : uint = inst::bits;
@@ -36,7 +34,7 @@ pub fn sub(x: T, y: T) -> T { x - y }
#[inline(always)]
pub fn mul(x: T, y: T) -> T { x * y }
#[inline(always)]
-pub fn div(x: T, y: T) -> T { x / y }
+pub fn quot(x: T, y: T) -> T { x / y }
#[inline(always)]
pub fn rem(x: T, y: T) -> T { x % y }
@@ -141,63 +139,71 @@ impl num::One for T {
}
#[cfg(notest)]
-impl ops::Add for T {
- #[inline(always)]
+impl Add for T {
fn add(&self, other: &T) -> T { *self + *other }
}
#[cfg(notest)]
-impl ops::Sub for T {
- #[inline(always)]
+impl Sub for T {
fn sub(&self, other: &T) -> T { *self - *other }
}
#[cfg(notest)]
-impl ops::Mul for T {
- #[inline(always)]
+impl Mul for T {
fn mul(&self, other: &T) -> T { *self * *other }
}
-#[cfg(notest)]
-impl ops::Div for T {
- #[inline(always)]
+#[cfg(stage0,notest)]
+impl Div for T {
fn div(&self, other: &T) -> T { *self / *other }
}
-#[cfg(notest)]
-impl ops::Modulo for T {
+#[cfg(stage1,notest)]
+#[cfg(stage2,notest)]
+#[cfg(stage3,notest)]
+impl Quot for T {
#[inline(always)]
+ fn quot(&self, other: &T) -> T { *self / *other }
+}
+#[cfg(stage0,notest)]
+impl Modulo for T {
fn modulo(&self, other: &T) -> T { *self % *other }
}
-#[cfg(notest)]
-impl ops::Neg for T {
+#[cfg(stage1,notest)]
+#[cfg(stage2,notest)]
+#[cfg(stage3,notest)]
+impl Rem for T {
#[inline(always)]
+ fn rem(&self, other: &T) -> T { *self % *other }
+}
+#[cfg(notest)]
+impl Neg for T {
fn neg(&self) -> T { -*self }
}
#[cfg(notest)]
-impl ops::BitOr for T {
+impl BitOr for T {
#[inline(always)]
fn bitor(&self, other: &T) -> T { *self | *other }
}
#[cfg(notest)]
-impl ops::BitAnd for T {
+impl BitAnd for T {
#[inline(always)]
fn bitand(&self, other: &T) -> T { *self & *other }
}
#[cfg(notest)]
-impl ops::BitXor for T {
+impl BitXor for T {
#[inline(always)]
fn bitxor(&self, other: &T) -> T { *self ^ *other }
}
#[cfg(notest)]
-impl ops::Shl for T {
+impl Shl for T {
#[inline(always)]
fn shl(&self, other: &T) -> T { *self << *other }
}
#[cfg(notest)]
-impl ops::Shr for T {
+impl Shr for T {
#[inline(always)]
fn shr(&self, other: &T) -> T { *self >> *other }
}
#[cfg(notest)]
-impl ops::Not for T {
+impl Not for T {
#[inline(always)]
fn not(&self) -> T { !*self }
}
diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs
index 4d89d8a957c..465a9330f74 100644
--- a/src/libcore/ops.rs
+++ b/src/libcore/ops.rs
@@ -31,14 +31,30 @@ pub trait Mul {
}
#[lang="div"]
+#[cfg(stage0)]
pub trait Div {
fn div(&self, rhs: &RHS) -> Result;
}
+#[lang="quot"]
+#[cfg(stage1)]
+#[cfg(stage2)]
+#[cfg(stage3)]
+pub trait Quot {
+ fn quot(&self, rhs: &RHS) -> Result;
+}
#[lang="modulo"]
+#[cfg(stage0)]
pub trait Modulo {
fn modulo(&self, rhs: &RHS) -> Result;
}
+#[lang="rem"]
+#[cfg(stage1)]
+#[cfg(stage2)]
+#[cfg(stage3)]
+pub trait Rem {
+ fn rem(&self, rhs: &RHS) -> Result;
+}
#[lang="neg"]
pub trait Neg {
diff --git a/src/libcore/prelude.rs b/src/libcore/prelude.rs
index 822fb2e476b..7d8b3edcab1 100644
--- a/src/libcore/prelude.rs
+++ b/src/libcore/prelude.rs
@@ -14,7 +14,12 @@
pub use either::{Either, Left, Right};
pub use kinds::{Const, Copy, Owned, Durable};
+#[cfg(stage0)]
pub use ops::{Add, Sub, Mul, Div, Modulo, Neg, Not};
+#[cfg(stage1)]
+#[cfg(stage2)]
+#[cfg(stage3)]
+pub use ops::{Add, Sub, Mul, Quot, Rem, Neg, Not};
pub use ops::{BitAnd, BitOr, BitXor};
pub use ops::{Drop};
pub use ops::{Shl, Shr, Index};
diff --git a/src/librustc/middle/const_eval.rs b/src/librustc/middle/const_eval.rs
index 5148ea7fba4..c1cc01ed05a 100644
--- a/src/librustc/middle/const_eval.rs
+++ b/src/librustc/middle/const_eval.rs
@@ -283,7 +283,7 @@ pub fn eval_const_expr_partial(tcx: middle::ty::ctxt, e: @expr)
add => Ok(const_float(a + b)),
subtract => Ok(const_float(a - b)),
mul => Ok(const_float(a * b)),
- div => Ok(const_float(a / b)),
+ quot => Ok(const_float(a / b)),
rem => Ok(const_float(a % b)),
eq => fromb(a == b),
lt => fromb(a < b),
@@ -299,9 +299,9 @@ pub fn eval_const_expr_partial(tcx: middle::ty::ctxt, e: @expr)
add => Ok(const_int(a + b)),
subtract => Ok(const_int(a - b)),
mul => Ok(const_int(a * b)),
- div if b == 0 => Err(~"divide by zero"),
- div => Ok(const_int(a / b)),
- rem if b == 0 => Err(~"modulo zero"),
+ quot if b == 0 => Err(~"quotient zero"),
+ quot => Ok(const_int(a / b)),
+ rem if b == 0 => Err(~"remainder zero"),
rem => Ok(const_int(a % b)),
and | bitand => Ok(const_int(a & b)),
or | bitor => Ok(const_int(a | b)),
@@ -321,9 +321,9 @@ pub fn eval_const_expr_partial(tcx: middle::ty::ctxt, e: @expr)
add => Ok(const_uint(a + b)),
subtract => Ok(const_uint(a - b)),
mul => Ok(const_uint(a * b)),
- div if b == 0 => Err(~"divide by zero"),
- div => Ok(const_uint(a / b)),
- rem if b == 0 => Err(~"modulo zero"),
+ quot if b == 0 => Err(~"quotient zero"),
+ quot => Ok(const_uint(a / b)),
+ rem if b == 0 => Err(~"remainder zero"),
rem => Ok(const_uint(a % b)),
and | bitand => Ok(const_uint(a & b)),
or | bitor => Ok(const_uint(a | b)),
diff --git a/src/librustc/middle/kind.rs b/src/librustc/middle/kind.rs
index 390ffded2fe..0558df60b73 100644
--- a/src/librustc/middle/kind.rs
+++ b/src/librustc/middle/kind.rs
@@ -480,7 +480,7 @@ pub fn check_durable(tcx: ty::ctxt, ty: ty::t, sp: span) -> bool {
/// This is rather subtle. When we are casting a value to a instantiated
/// trait like `a as trait<'r>`, regionck already ensures that any borrowed
-/// pointers that appear in the type of `a` are bounded by `'r` (ed.: modulo
+/// pointers that appear in the type of `a` are bounded by `'r` (ed.: rem
/// FIXME(#5723)). However, it is possible that there are *type parameters*
/// in the type of `a`, and those *type parameters* may have borrowed pointers
/// within them. We have to guarantee that the regions which appear in those
diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs
index 435cb896ac7..5b302108ef0 100644
--- a/src/librustc/middle/lang_items.rs
+++ b/src/librustc/middle/lang_items.rs
@@ -45,8 +45,8 @@ pub enum LangItem {
AddTraitLangItem, // 5
SubTraitLangItem, // 6
MulTraitLangItem, // 7
- DivTraitLangItem, // 8
- ModuloTraitLangItem, // 9
+ QuotTraitLangItem, // 8
+ RemTraitLangItem, // 9
NegTraitLangItem, // 10
NotTraitLangItem, // 11
BitXorTraitLangItem, // 12
@@ -108,8 +108,8 @@ pub impl LanguageItems {
5 => "add",
6 => "sub",
7 => "mul",
- 8 => "div",
- 9 => "modulo",
+ 8 => "quot",
+ 9 => "rem",
10 => "neg",
11 => "not",
12 => "bitxor",
@@ -170,11 +170,11 @@ pub impl LanguageItems {
pub fn mul_trait(&const self) -> def_id {
self.items[MulTraitLangItem as uint].get()
}
- pub fn div_trait(&const self) -> def_id {
- self.items[DivTraitLangItem as uint].get()
+ pub fn quot_trait(&const self) -> def_id {
+ self.items[QuotTraitLangItem as uint].get()
}
- pub fn modulo_trait(&const self) -> def_id {
- self.items[ModuloTraitLangItem as uint].get()
+ pub fn rem_trait(&const self) -> def_id {
+ self.items[RemTraitLangItem as uint].get()
}
pub fn neg_trait(&const self) -> def_id {
self.items[NegTraitLangItem as uint].get()
@@ -271,8 +271,8 @@ fn LanguageItemCollector<'r>(crate: @crate,
item_refs.insert(@~"add", AddTraitLangItem as uint);
item_refs.insert(@~"sub", SubTraitLangItem as uint);
item_refs.insert(@~"mul", MulTraitLangItem as uint);
- item_refs.insert(@~"div", DivTraitLangItem as uint);
- item_refs.insert(@~"modulo", ModuloTraitLangItem as uint);
+ item_refs.insert(@~"quot", QuotTraitLangItem as uint);
+ item_refs.insert(@~"rem", RemTraitLangItem as uint);
item_refs.insert(@~"neg", NegTraitLangItem as uint);
item_refs.insert(@~"not", NotTraitLangItem as uint);
item_refs.insert(@~"bitxor", BitXorTraitLangItem as uint);
diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs
index 3c158c0d081..41b372119cd 100644
--- a/src/librustc/middle/resolve.rs
+++ b/src/librustc/middle/resolve.rs
@@ -37,7 +37,7 @@ use syntax::ast::{def_upvar, def_use, def_variant, expr, expr_assign_op};
use syntax::ast::{expr_binary, expr_break, expr_field};
use syntax::ast::{expr_fn_block, expr_index, expr_method_call, expr_path};
use syntax::ast::{def_prim_ty, def_region, def_self, def_ty, def_ty_param};
-use syntax::ast::{def_upvar, def_use, def_variant, div, eq};
+use syntax::ast::{def_upvar, def_use, def_variant, quot, eq};
use syntax::ast::{expr, expr_again, expr_assign_op};
use syntax::ast::{expr_index, expr_loop};
use syntax::ast::{expr_path, expr_struct, expr_unary, fn_decl};
@@ -4899,13 +4899,13 @@ pub impl Resolver {
self.add_fixed_trait_for_expr(expr.id,
self.lang_items.mul_trait());
}
- expr_binary(div, _, _) | expr_assign_op(div, _, _) => {
+ expr_binary(quot, _, _) | expr_assign_op(quot, _, _) => {
self.add_fixed_trait_for_expr(expr.id,
- self.lang_items.div_trait());
+ self.lang_items.quot_trait());
}
expr_binary(rem, _, _) | expr_assign_op(rem, _, _) => {
self.add_fixed_trait_for_expr(expr.id,
- self.lang_items.modulo_trait());
+ self.lang_items.rem_trait());
}
expr_binary(bitxor, _, _) | expr_assign_op(bitxor, _, _) => {
self.add_fixed_trait_for_expr(expr.id,
diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs
index e1c60234f0f..3ad021b2f51 100644
--- a/src/librustc/middle/trans/base.rs
+++ b/src/librustc/middle/trans/base.rs
@@ -782,12 +782,12 @@ pub fn cast_shift_rhs(op: ast::binop,
}
}
-pub fn fail_if_zero(cx: block, span: span, divmod: ast::binop,
+pub fn fail_if_zero(cx: block, span: span, quotrem: ast::binop,
rhs: ValueRef, rhs_t: ty::t) -> block {
- let text = if divmod == ast::div {
- @~"divide by zero"
+ let text = if quotrem == ast::quot {
+ @~"quotient zero"
} else {
- @~"modulo zero"
+ @~"remainder zero"
};
let is_zero = match ty::get(rhs_t).sty {
ty::ty_int(t) => {
diff --git a/src/librustc/middle/trans/consts.rs b/src/librustc/middle/trans/consts.rs
index c5e708569dc..d0aeec89750 100644
--- a/src/librustc/middle/trans/consts.rs
+++ b/src/librustc/middle/trans/consts.rs
@@ -272,7 +272,7 @@ fn const_expr_unadjusted(cx: @CrateContext, e: @ast::expr) -> ValueRef {
if is_float { llvm::LLVMConstFMul(te1, te2) }
else { llvm::LLVMConstMul(te1, te2) }
}
- ast::div => {
+ ast::quot => {
if is_float { llvm::LLVMConstFDiv(te1, te2) }
else if signed { llvm::LLVMConstSDiv(te1, te2) }
else { llvm::LLVMConstUDiv(te1, te2) }
diff --git a/src/librustc/middle/trans/expr.rs b/src/librustc/middle/trans/expr.rs
index ba6965f0eae..4b4d0869a3e 100644
--- a/src/librustc/middle/trans/expr.rs
+++ b/src/librustc/middle/trans/expr.rs
@@ -1437,7 +1437,7 @@ fn trans_eager_binop(bcx: block,
if is_float { FMul(bcx, lhs, rhs) }
else { Mul(bcx, lhs, rhs) }
}
- ast::div => {
+ ast::quot => {
if is_float {
FDiv(bcx, lhs, rhs)
} else {
diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs
index 95d0fa984ae..033fbecc08b 100644
--- a/src/librustc/middle/ty.rs
+++ b/src/librustc/middle/ty.rs
@@ -4255,7 +4255,7 @@ pub fn is_binopable(_cx: ctxt, ty: t, op: ast::binop) -> bool {
ast::add => opcat_add,
ast::subtract => opcat_sub,
ast::mul => opcat_mult,
- ast::div => opcat_mult,
+ ast::quot => opcat_mult,
ast::rem => opcat_mult,
ast::and => opcat_logic,
ast::or => opcat_logic,
diff --git a/src/libstd/base64.rs b/src/libstd/base64.rs
index e90f0fb3c81..cbdd2b19d27 100644
--- a/src/libstd/base64.rs
+++ b/src/libstd/base64.rs
@@ -118,7 +118,7 @@ pub trait FromBase64 {
impl FromBase64 for ~[u8] {
/**
* Convert base64 `u8` vector into u8 byte values.
- * Every 4 encoded characters is converted into 3 octets, modulo padding.
+ * Every 4 encoded characters is converted into 3 octets, rem padding.
*
* *Example*:
*
diff --git a/src/libstd/num/bigint.rs b/src/libstd/num/bigint.rs
index ec5d2cded8d..08c65d190bf 100644
--- a/src/libstd/num/bigint.rs
+++ b/src/libstd/num/bigint.rs
@@ -262,16 +262,16 @@ impl Mul for BigUint {
}
}
-impl Div for BigUint {
- fn div(&self, other: &BigUint) -> BigUint {
- let (d, _) = self.divmod(other);
+impl Quot for BigUint {
+ fn quot(&self, other: &BigUint) -> BigUint {
+ let (d, _) = self.quot_rem(other);
return d;
}
}
-impl Modulo for BigUint {
- fn modulo(&self, other: &BigUint) -> BigUint {
- let (_, m) = self.divmod(other);
+impl Rem for BigUint {
+ fn rem(&self, other: &BigUint) -> BigUint {
+ let (_, m) = self.quot_rem(other);
return m;
}
}
@@ -304,7 +304,7 @@ impl ToStrRadix for BigUint {
let mut result = ~[];
let mut r = n;
while r > divider {
- let (d, r0) = r.divmod(÷r);
+ let (d, r0) = r.quot_rem(÷r);
result += [r0.to_uint() as BigDigit];
r = d;
}
@@ -384,7 +384,7 @@ pub impl BigUint {
fn abs(&self) -> BigUint { copy *self }
- fn divmod(&self, other: &BigUint) -> (BigUint, BigUint) {
+ fn quot_rem(&self, other: &BigUint) -> (BigUint, BigUint) {
if other.is_zero() { fail!() }
if self.is_zero() { return (Zero::zero(), Zero::zero()); }
if *other == One::one() { return (copy *self, Zero::zero()); }
@@ -402,10 +402,10 @@ pub impl BigUint {
shift += 1;
}
assert!(shift < BigDigit::bits);
- let (d, m) = divmod_inner(self << shift, other << shift);
+ let (d, m) = quot_rem_inner(self << shift, other << shift);
return (d, m >> shift);
- fn divmod_inner(a: BigUint, b: BigUint) -> (BigUint, BigUint) {
+ fn quot_rem_inner(a: BigUint, b: BigUint) -> (BigUint, BigUint) {
let mut r = a;
let mut d = Zero::zero::();
let mut n = 1;
@@ -464,7 +464,7 @@ pub impl BigUint {
return r;
}
fn quotrem(&self, other: &BigUint) -> (BigUint, BigUint) {
- self.divmod(other)
+ self.quot_rem(other)
}
fn is_zero(&self) -> bool { self.data.is_empty() }
@@ -737,16 +737,16 @@ impl Mul for BigInt {
}
}
-impl Div for BigInt {
- fn div(&self, other: &BigInt) -> BigInt {
- let (d, _) = self.divmod(other);
+impl Quot for BigInt {
+ fn quot(&self, other: &BigInt) -> BigInt {
+ let (d, _) = self.quot_rem(other);
return d;
}
}
-impl Modulo for BigInt {
- fn modulo(&self, other: &BigInt) -> BigInt {
- let (_, m) = self.divmod(other);
+impl Rem for BigInt {
+ fn rem(&self, other: &BigInt) -> BigInt {
+ let (_, m) = self.quot_rem(other);
return m;
}
}
@@ -841,9 +841,9 @@ pub impl BigInt {
BigInt::from_biguint(Plus, copy self.data)
}
- fn divmod(&self, other: &BigInt) -> (BigInt, BigInt) {
+ fn quot_rem(&self, other: &BigInt) -> (BigInt, BigInt) {
// m.sign == other.sign
- let (d_ui, m_ui) = self.data.divmod(&other.data);
+ let (d_ui, m_ui) = self.data.quot_rem(&other.data);
let d = BigInt::from_biguint(Plus, d_ui),
m = BigInt::from_biguint(Plus, m_ui);
match (self.sign, other.sign) {
@@ -1150,7 +1150,7 @@ mod biguint_tests {
(&[ 0, 0, 1], &[ 0, 0, 0, 1], &[0, 0, 0, 0, 0, 1])
];
- static divmod_quadruples: &'static [(&'static [BigDigit],
+ static quot_rem_quadruples: &'static [(&'static [BigDigit],
&'static [BigDigit],
&'static [BigDigit],
&'static [BigDigit])]
@@ -1174,7 +1174,7 @@ mod biguint_tests {
assert!(b * a == c);
}
- for divmod_quadruples.each |elm| {
+ for quot_rem_quadruples.each |elm| {
let (aVec, bVec, cVec, dVec) = *elm;
let a = BigUint::from_slice(aVec);
let b = BigUint::from_slice(bVec);
@@ -1187,7 +1187,7 @@ mod biguint_tests {
}
#[test]
- fn test_divmod() {
+ fn test_quot_rem() {
for mul_triples.each |elm| {
let (aVec, bVec, cVec) = *elm;
let a = BigUint::from_slice(aVec);
@@ -1195,21 +1195,21 @@ mod biguint_tests {
let c = BigUint::from_slice(cVec);
if a.is_not_zero() {
- assert!(c.divmod(&a) == (b, Zero::zero()));
+ assert!(c.quot_rem(&a) == (b, Zero::zero()));
}
if b.is_not_zero() {
- assert!(c.divmod(&b) == (a, Zero::zero()));
+ assert!(c.quot_rem(&b) == (a, Zero::zero()));
}
}
- for divmod_quadruples.each |elm| {
+ for quot_rem_quadruples.each |elm| {
let (aVec, bVec, cVec, dVec) = *elm;
let a = BigUint::from_slice(aVec);
let b = BigUint::from_slice(bVec);
let c = BigUint::from_slice(cVec);
let d = BigUint::from_slice(dVec);
- if b.is_not_zero() { assert!(a.divmod(&b) == (c, d)); }
+ if b.is_not_zero() { assert!(a.quot_rem(&b) == (c, d)); }
}
}
@@ -1516,7 +1516,7 @@ mod bigint_tests {
(&[ 0, 0, 1], &[ 0, 0, 0, 1], &[0, 0, 0, 0, 0, 1])
];
- static divmod_quadruples: &'static [(&'static [BigDigit],
+ static quot_rem_quadruples: &'static [(&'static [BigDigit],
&'static [BigDigit],
&'static [BigDigit],
&'static [BigDigit])]
@@ -1543,7 +1543,7 @@ mod bigint_tests {
assert!((-b) * a == -c);
}
- for divmod_quadruples.each |elm| {
+ for quot_rem_quadruples.each |elm| {
let (aVec, bVec, cVec, dVec) = *elm;
let a = BigInt::from_slice(Plus, aVec);
let b = BigInt::from_slice(Plus, bVec);
@@ -1556,9 +1556,9 @@ mod bigint_tests {
}
#[test]
- fn test_divmod() {
+ fn test_quot_rem() {
fn check_sub(a: &BigInt, b: &BigInt, ans_d: &BigInt, ans_m: &BigInt) {
- let (d, m) = a.divmod(b);
+ let (d, m) = a.quot_rem(b);
if m.is_not_zero() {
assert!(m.sign == b.sign);
}
@@ -1592,7 +1592,7 @@ mod bigint_tests {
if b.is_not_zero() { check(&c, &b, &a, &Zero::zero()); }
}
- for divmod_quadruples.each |elm| {
+ for quot_rem_quadruples.each |elm| {
let (aVec, bVec, cVec, dVec) = *elm;
let a = BigInt::from_slice(Plus, aVec);
let b = BigInt::from_slice(Plus, bVec);
@@ -1635,7 +1635,7 @@ mod bigint_tests {
if b.is_not_zero() { check(&c, &b, &a, &Zero::zero()); }
}
- for divmod_quadruples.each |elm| {
+ for quot_rem_quadruples.each |elm| {
let (aVec, bVec, cVec, dVec) = *elm;
let a = BigInt::from_slice(Plus, aVec);
let b = BigInt::from_slice(Plus, bVec);
diff --git a/src/libstd/num/complex.rs b/src/libstd/num/complex.rs
index 949850f3ca6..ef7fa397d7f 100644
--- a/src/libstd/num/complex.rs
+++ b/src/libstd/num/complex.rs
@@ -32,8 +32,7 @@ pub type Complex = Cmplx;
pub type Complex32 = Cmplx;
pub type Complex64 = Cmplx;
-impl + Sub + Mul + Div + Neg>
- Cmplx {
+impl Cmplx {
/// Create a new Cmplx
#[inline]
pub fn new(re: T, im: T) -> Cmplx {
@@ -80,24 +79,21 @@ impl + Sub + Mul + Div + Neg>
/* arithmetic */
// (a + i b) + (c + i d) == (a + c) + i (b + d)
-impl + Sub + Mul + Div + Neg>
- Add, Cmplx> for Cmplx {
+impl Add, Cmplx> for Cmplx {
#[inline]
fn add(&self, other: &Cmplx) -> Cmplx {
Cmplx::new(self.re + other.re, self.im + other.im)
}
}
// (a + i b) - (c + i d) == (a - c) + i (b - d)
-impl + Sub + Mul + Div + Neg>
- Sub, Cmplx> for Cmplx {
+impl Sub, Cmplx> for Cmplx {
#[inline]
fn sub(&self, other: &Cmplx) -> Cmplx {
Cmplx::new(self.re - other.re, self.im - other.im)
}
}
// (a + i b) * (c + i d) == (a*c - b*d) + i (a*d + b*c)
-impl + Sub + Mul + Div + Neg>
- Mul, Cmplx> for Cmplx {
+impl Mul, Cmplx> for Cmplx {
#[inline]
fn mul(&self, other: &Cmplx) -> Cmplx {
Cmplx::new(self.re*other.re - self.im*other.im,
@@ -107,18 +103,16 @@ impl + Sub + Mul + Div + Neg>
// (a + i b) / (c + i d) == [(a + i b) * (c - i d)] / (c*c + d*d)
// == [(a*c + b*d) / (c*c + d*d)] + i [(b*c - a*d) / (c*c + d*d)]
-impl + Sub + Mul + Div + Neg>
- Div, Cmplx> for Cmplx {
+impl Quot, Cmplx> for Cmplx {
#[inline]
- fn div(&self, other: &Cmplx) -> Cmplx {
+ fn quot(&self, other: &Cmplx) -> Cmplx {
let norm_sqr = other.norm_sqr();
Cmplx::new((self.re*other.re + self.im*other.im) / norm_sqr,
(self.im*other.re - self.re*other.im) / norm_sqr)
}
}
-impl + Sub + Mul + Div + Neg>
- Neg> for Cmplx {
+impl Neg> for Cmplx {
#[inline]
fn neg(&self) -> Cmplx {
Cmplx::new(-self.re, -self.im)
@@ -126,16 +120,14 @@ impl + Sub + Mul + Div