diff options
| author | bors <bors@rust-lang.org> | 2014-12-15 22:11:44 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-12-15 22:11:44 +0000 |
| commit | 0669a432a2e09ad08886cb2138dbe9f5d681fb7f (patch) | |
| tree | 5183544df317d80a6bce406242596dd997e61b64 /src/libcoretest | |
| parent | 92e9e70d15bcf8d29890bf93793be402ad629229 (diff) | |
| parent | 89d2061c8f1cc2bcd5e9bb8a97e214f482d5ff2c (diff) | |
| download | rust-0669a432a2e09ad08886cb2138dbe9f5d681fb7f.tar.gz rust-0669a432a2e09ad08886cb2138dbe9f5d681fb7f.zip | |
auto merge of #19448 : japaric/rust/binops-by-value, r=nikomatsakis
- The following operator traits now take their arguments by value: `Add`, `Sub`, `Mul`, `Div`, `Rem`, `BitAnd`, `BitOr`, `BitXor`, `Shl`, `Shr`. This breaks all existing implementations of these traits. - The binary operation `a OP b` now "desugars" to `OpTrait::op_method(a, b)` and consumes both arguments. - `String` and `Vec` addition have been changed to reuse the LHS owned value, and to avoid internal cloning. Only the following asymmetric operations are available: `String + &str` and `Vec<T> + &[T]`, which are now a short-hand for the "append" operation. [breaking-change] --- This passes `make check` locally. I haven't touch the unary operators in this PR, but converting them to by value should be very similar to this PR. I can work on them after this gets the thumbs up. @nikomatsakis r? the compiler changes @aturon r? the library changes. I think the only controversial bit is the semantic change of the `Vec`/`String` `Add` implementation. cc #19148
Diffstat (limited to 'src/libcoretest')
| -rw-r--r-- | src/libcoretest/num/int_macros.rs | 10 | ||||
| -rw-r--r-- | src/libcoretest/num/mod.rs | 22 | ||||
| -rw-r--r-- | src/libcoretest/num/uint_macros.rs | 10 |
3 files changed, 22 insertions, 20 deletions
diff --git a/src/libcoretest/num/int_macros.rs b/src/libcoretest/num/int_macros.rs index e25f10bd0da..87e2fe75299 100644 --- a/src/libcoretest/num/int_macros.rs +++ b/src/libcoretest/num/int_macros.rs @@ -64,11 +64,11 @@ mod tests { #[test] fn test_bitwise_operators() { - assert!(0b1110 as $T == (0b1100 as $T).bitor(&(0b1010 as $T))); - assert!(0b1000 as $T == (0b1100 as $T).bitand(&(0b1010 as $T))); - assert!(0b0110 as $T == (0b1100 as $T).bitxor(&(0b1010 as $T))); - assert!(0b1110 as $T == (0b0111 as $T).shl(&1)); - assert!(0b0111 as $T == (0b1110 as $T).shr(&1)); + assert!(0b1110 as $T == (0b1100 as $T).bitor(0b1010 as $T)); + assert!(0b1000 as $T == (0b1100 as $T).bitand(0b1010 as $T)); + assert!(0b0110 as $T == (0b1100 as $T).bitxor(0b1010 as $T)); + assert!(0b1110 as $T == (0b0111 as $T).shl(1)); + assert!(0b0111 as $T == (0b1110 as $T).shr(1)); assert!(-(0b11 as $T) - (1 as $T) == (0b11 as $T).not()); } diff --git a/src/libcoretest/num/mod.rs b/src/libcoretest/num/mod.rs index 6ee3633d36c..b7f8b81f996 100644 --- a/src/libcoretest/num/mod.rs +++ b/src/libcoretest/num/mod.rs @@ -12,6 +12,7 @@ use core::cmp::PartialEq; use core::fmt::Show; use core::num::{NumCast, cast}; use core::ops::{Add, Sub, Mul, Div, Rem}; +use core::kinds::Copy; mod int_macros; mod i8; @@ -32,18 +33,19 @@ pub fn test_num<T>(ten: T, two: T) where + Add<T, T> + Sub<T, T> + Mul<T, T> + Div<T, T> + Rem<T, T> + Show + + Copy { - assert_eq!(ten.add(&two), cast(12i).unwrap()); - assert_eq!(ten.sub(&two), cast(8i).unwrap()); - assert_eq!(ten.mul(&two), cast(20i).unwrap()); - assert_eq!(ten.div(&two), cast(5i).unwrap()); - assert_eq!(ten.rem(&two), cast(0i).unwrap()); + assert_eq!(ten.add(two), cast(12i).unwrap()); + assert_eq!(ten.sub(two), cast(8i).unwrap()); + assert_eq!(ten.mul(two), cast(20i).unwrap()); + assert_eq!(ten.div(two), cast(5i).unwrap()); + assert_eq!(ten.rem(two), cast(0i).unwrap()); - assert_eq!(ten.add(&two), ten + two); - assert_eq!(ten.sub(&two), ten - two); - assert_eq!(ten.mul(&two), ten * two); - assert_eq!(ten.div(&two), ten / two); - assert_eq!(ten.rem(&two), ten % two); + assert_eq!(ten.add(two), ten + two); + assert_eq!(ten.sub(two), ten - two); + assert_eq!(ten.mul(two), ten * two); + assert_eq!(ten.div(two), ten / two); + assert_eq!(ten.rem(two), ten % two); } #[cfg(test)] diff --git a/src/libcoretest/num/uint_macros.rs b/src/libcoretest/num/uint_macros.rs index 01a88119b64..5657a43de19 100644 --- a/src/libcoretest/num/uint_macros.rs +++ b/src/libcoretest/num/uint_macros.rs @@ -31,11 +31,11 @@ mod tests { #[test] fn test_bitwise_operators() { - assert!(0b1110 as $T == (0b1100 as $T).bitor(&(0b1010 as $T))); - assert!(0b1000 as $T == (0b1100 as $T).bitand(&(0b1010 as $T))); - assert!(0b0110 as $T == (0b1100 as $T).bitxor(&(0b1010 as $T))); - assert!(0b1110 as $T == (0b0111 as $T).shl(&1u)); - assert!(0b0111 as $T == (0b1110 as $T).shr(&1u)); + assert!(0b1110 as $T == (0b1100 as $T).bitor(0b1010 as $T)); + assert!(0b1000 as $T == (0b1100 as $T).bitand(0b1010 as $T)); + assert!(0b0110 as $T == (0b1100 as $T).bitxor(0b1010 as $T)); + assert!(0b1110 as $T == (0b0111 as $T).shl(1u)); + assert!(0b0111 as $T == (0b1110 as $T).shr(1u)); assert!(MAX - (0b1011 as $T) == (0b1011 as $T).not()); } |
