]> git.lizzy.rs Git - rust.git/commitdiff
use assoc types in unop traits
authorJorge Aparicio <japaricious@gmail.com>
Sat, 3 Jan 2015 03:56:24 +0000 (22:56 -0500)
committerJorge Aparicio <japaricious@gmail.com>
Sat, 3 Jan 2015 21:29:22 +0000 (16:29 -0500)
src/libcore/num/mod.rs
src/libcore/ops.rs
src/libstd/bitflags.rs
src/libstd/time/duration.rs
src/test/compile-fail/unop-move-semantics.rs
src/test/run-pass/operator-overloading.rs

index c642ff0c2e48f9080d300d90f49003d1151afb81..254788f9a75f193b83ba19d964a721eef28f4126 100644 (file)
@@ -58,7 +58,7 @@ pub trait Int
     + Mul<Output=Self>
     + Div<Output=Self>
     + Rem<Output=Self>
-    + Not<Self>
+    + Not<Output=Self>
     + BitAnd<Output=Self>
     + BitOr<Output=Self>
     + BitXor<Output=Self>
@@ -613,7 +613,7 @@ fn checked_div(self, v: $T) -> Option<$T> {
 #[unstable = "recently settled as part of numerics reform"]
 pub trait SignedInt
     : Int
-    + Neg<Self>
+    + Neg<Output=Self>
 {
     /// Computes the absolute value of `self`. `Int::min_value()` will be
     /// returned if the number is `Int::min_value()`.
@@ -1245,7 +1245,7 @@ pub trait Float
     + NumCast
     + PartialOrd
     + PartialEq
-    + Neg<Self>
+    + Neg<Output=Self>
     + Add<Output=Self>
     + Sub<Output=Self>
     + Mul<Output=Self>
@@ -1718,7 +1718,7 @@ macro_rules! trait_impl {
 #[deprecated = "Generalised numbers are no longer supported"]
 #[allow(deprecated)]
 pub trait Num: PartialEq + Zero + One
-             + Neg<Self>
+             + Neg<Output=Self>
              + Add<Output=Self>
              + Sub<Output=Self>
              + Mul<Output=Self>
index 1bf22d65ffba479295aedcb2a788e18239e2959b..642376f1d8e94ca1b3cb034dd7276b304e413598 100644 (file)
@@ -360,13 +360,17 @@ fn rem(self, other: $t) -> $t {
 /// `neg`, and therefore, `main` prints `Negating!`.
 ///
 /// ```
+/// #![feature(associated_types)]
+///
 /// use std::ops::Neg;
 ///
 /// struct Foo;
 ///
 /// impl Copy for Foo {}
 ///
-/// impl Neg<Foo> for Foo {
+/// impl Neg for Foo {
+///     type Output = Foo;
+///
 ///     fn neg(self) -> Foo {
 ///         println!("Negating!");
 ///         self
@@ -378,14 +382,18 @@ fn rem(self, other: $t) -> $t {
 /// }
 /// ```
 #[lang="neg"]
-pub trait Neg<Result> {
+pub trait Neg {
+    type Output;
+
     /// The method for the unary `-` operator
-    fn neg(self) -> Result;
+    fn neg(self) -> Self::Output;
 }
 
 macro_rules! neg_impl {
     ($($t:ty)*) => ($(
-        impl Neg<$t> for $t {
+        impl Neg for $t {
+            type Output = $t;
+
             #[inline]
             fn neg(self) -> $t { -self }
         }
@@ -394,7 +402,9 @@ fn neg(self) -> $t { -self }
 
 macro_rules! neg_uint_impl {
     ($t:ty, $t_signed:ty) => {
-        impl Neg<$t> for $t {
+        impl Neg for $t {
+            type Output = $t;
+
             #[inline]
             fn neg(self) -> $t { -(self as $t_signed) as $t }
         }
@@ -418,13 +428,17 @@ fn neg(self) -> $t { -(self as $t_signed) as $t }
 /// `not`, and therefore, `main` prints `Not-ing!`.
 ///
 /// ```
+/// #![feature(associated_types)]
+///
 /// use std::ops::Not;
 ///
 /// struct Foo;
 ///
 /// impl Copy for Foo {}
 ///
-/// impl Not<Foo> for Foo {
+/// impl Not for Foo {
+///     type Output = Foo;
+///
 ///     fn not(self) -> Foo {
 ///         println!("Not-ing!");
 ///         self
@@ -436,14 +450,18 @@ fn neg(self) -> $t { -(self as $t_signed) as $t }
 /// }
 /// ```
 #[lang="not"]
-pub trait Not<Result> {
+pub trait Not {
+    type Output;
+
     /// The method for the unary `!` operator
-    fn not(self) -> Result;
+    fn not(self) -> Self::Output;
 }
 
 macro_rules! not_impl {
     ($($t:ty)*) => ($(
-        impl Not<$t> for $t {
+        impl Not for $t {
+            type Output = $t;
+
             #[inline]
             fn not(self) -> $t { !self }
         }
index a9c74823dde9e99d3fbc32fb91ca72b0bf761bb1..16bc6b16598e046c90949dcfde7e6b5d5692a943 100644 (file)
@@ -249,7 +249,9 @@ fn sub(self, other: $BitFlags) -> $BitFlags {
             }
         }
 
-        impl ::std::ops::Not<$BitFlags> for $BitFlags {
+        impl ::std::ops::Not for $BitFlags {
+            type Output = $BitFlags;
+
             /// Returns the complement of this set of flags.
             #[inline]
             fn not(self) -> $BitFlags {
index 1e148105cc62759de859396de08a13092f900093..41a130492c0470601970d74e7c86d8d20016bcc5 100644 (file)
@@ -262,7 +262,9 @@ pub fn is_zero(&self) -> bool {
     }
 }
 
-impl Neg<Duration> for Duration {
+impl Neg for Duration {
+    type Output = Duration;
+
     #[inline]
     fn neg(self) -> Duration {
         if self.nanos == 0 {
index c458c539c0766f65875d26eefe748f33adf372a6..f8cbdb4e160bf4cc18cfa7fc3eddd1a3f0b4dce2 100644 (file)
 
 use std::ops::Not;
 
-fn move_then_borrow<T: Not<T> + Clone>(x: T) {
+fn move_then_borrow<T: Not<Output=T> + Clone>(x: T) {
     !x;
 
     x.clone();  //~ ERROR: use of moved value
 }
 
-fn move_borrowed<T: Not<T>>(x: T, mut y: T) {
+fn move_borrowed<T: Not<Output=T>>(x: T, mut y: T) {
     let m = &x;
     let n = &mut y;
 
@@ -27,7 +27,7 @@ fn move_borrowed<T: Not<T>>(x: T, mut y: T) {
     !y;  //~ ERROR: cannot move out of `y` because it is borrowed
 }
 
-fn illegal_dereference<T: Not<T>>(mut x: T, y: T) {
+fn illegal_dereference<T: Not<Output=T>>(mut x: T, y: T) {
     let m = &mut x;
     let n = &y;
 
index b23133c53daa5f37e0ad656ea292e53d19c69eaf..58c433e570e76fff9361ad409ef3dfeacc648839 100644 (file)
@@ -35,13 +35,17 @@ fn sub(self, other: Point) -> Point {
     }
 }
 
-impl ops::Neg<Point> for Point {
+impl ops::Neg for Point {
+    type Output = Point;
+
     fn neg(self) -> Point {
         Point {x: -self.x, y: -self.y}
     }
 }
 
-impl ops::Not<Point> for Point {
+impl ops::Not for Point {
+    type Output = Point;
+
     fn not(self) -> Point {
         Point {x: !self.x, y: !self.y }
     }