From 99017f82b6e41ed283199b88ddfc0990bb95d696 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Wed, 31 Dec 2014 15:45:13 -0500 Subject: use assoc types in binop traits --- src/libstd/bitflags.rs | 16 ++++++++++++---- src/libstd/collections/hash/set.rs | 16 ++++++++++++---- src/libstd/num/mod.rs | 6 +++--- src/libstd/time/duration.rs | 16 ++++++++++++---- 4 files changed, 39 insertions(+), 15 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/bitflags.rs b/src/libstd/bitflags.rs index c07531d3f32..a9c74823dde 100644 --- a/src/libstd/bitflags.rs +++ b/src/libstd/bitflags.rs @@ -209,7 +209,9 @@ macro_rules! bitflags { } } - impl ::std::ops::BitOr<$BitFlags, $BitFlags> for $BitFlags { + impl ::std::ops::BitOr for $BitFlags { + type Output = $BitFlags; + /// Returns the union of the two sets of flags. #[inline] fn bitor(self, other: $BitFlags) -> $BitFlags { @@ -217,7 +219,9 @@ macro_rules! bitflags { } } - impl ::std::ops::BitXor<$BitFlags, $BitFlags> for $BitFlags { + impl ::std::ops::BitXor for $BitFlags { + type Output = $BitFlags; + /// Returns the left flags, but with all the right flags toggled. #[inline] fn bitxor(self, other: $BitFlags) -> $BitFlags { @@ -225,7 +229,9 @@ macro_rules! bitflags { } } - impl ::std::ops::BitAnd<$BitFlags, $BitFlags> for $BitFlags { + impl ::std::ops::BitAnd for $BitFlags { + type Output = $BitFlags; + /// Returns the intersection between the two sets of flags. #[inline] fn bitand(self, other: $BitFlags) -> $BitFlags { @@ -233,7 +239,9 @@ macro_rules! bitflags { } } - impl ::std::ops::Sub<$BitFlags, $BitFlags> for $BitFlags { + impl ::std::ops::Sub for $BitFlags { + type Output = $BitFlags; + /// Returns the set difference of the two sets of flags. #[inline] fn sub(self, other: $BitFlags) -> $BitFlags { diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs index ea8298c48c8..4c6a74a78d5 100644 --- a/src/libstd/collections/hash/set.rs +++ b/src/libstd/collections/hash/set.rs @@ -630,7 +630,9 @@ impl, S, H: Hasher + Default> Default for HashSet { #[stable] impl<'a, 'b, T: Eq + Hash + Clone, S, H: Hasher + Default> -BitOr<&'b HashSet, HashSet> for &'a HashSet { +BitOr<&'b HashSet> for &'a HashSet { + type Output = HashSet; + /// Returns the union of `self` and `rhs` as a new `HashSet`. /// /// # Examples @@ -658,7 +660,9 @@ BitOr<&'b HashSet, HashSet> for &'a HashSet { #[stable] impl<'a, 'b, T: Eq + Hash + Clone, S, H: Hasher + Default> -BitAnd<&'b HashSet, HashSet> for &'a HashSet { +BitAnd<&'b HashSet> for &'a HashSet { + type Output = HashSet; + /// Returns the intersection of `self` and `rhs` as a new `HashSet`. /// /// # Examples @@ -686,7 +690,9 @@ BitAnd<&'b HashSet, HashSet> for &'a HashSet { #[stable] impl<'a, 'b, T: Eq + Hash + Clone, S, H: Hasher + Default> -BitXor<&'b HashSet, HashSet> for &'a HashSet { +BitXor<&'b HashSet> for &'a HashSet { + type Output = HashSet; + /// Returns the symmetric difference of `self` and `rhs` as a new `HashSet`. /// /// # Examples @@ -714,7 +720,9 @@ BitXor<&'b HashSet, HashSet> for &'a HashSet { #[stable] impl<'a, 'b, T: Eq + Hash + Clone, S, H: Hasher + Default> -Sub<&'b HashSet, HashSet> for &'a HashSet { +Sub<&'b HashSet> for &'a HashSet { + type Output = HashSet; + /// Returns the difference of `self` and `rhs` as a new `HashSet`. /// /// # Examples diff --git a/src/libstd/num/mod.rs b/src/libstd/num/mod.rs index 01aa21c692b..007d89a942d 100644 --- a/src/libstd/num/mod.rs +++ b/src/libstd/num/mod.rs @@ -127,9 +127,9 @@ pub fn abs_sub(x: T, y: T) -> T { #[cfg(test)] pub fn test_num(ten: T, two: T) where T: PartialEq + NumCast - + Add + Sub - + Mul + Div - + Rem + Show + + Add + Sub + + Mul + Div + + Rem + Show + Copy { assert_eq!(ten.add(two), cast(12i).unwrap()); diff --git a/src/libstd/time/duration.rs b/src/libstd/time/duration.rs index 51564b53976..1e148105cc6 100644 --- a/src/libstd/time/duration.rs +++ b/src/libstd/time/duration.rs @@ -273,7 +273,9 @@ impl Neg for Duration { } } -impl Add for Duration { +impl Add for Duration { + type Output = Duration; + fn add(self, rhs: Duration) -> Duration { let mut secs = self.secs + rhs.secs; let mut nanos = self.nanos + rhs.nanos; @@ -285,7 +287,9 @@ impl Add for Duration { } } -impl Sub for Duration { +impl Sub for Duration { + type Output = Duration; + fn sub(self, rhs: Duration) -> Duration { let mut secs = self.secs - rhs.secs; let mut nanos = self.nanos - rhs.nanos; @@ -297,7 +301,9 @@ impl Sub for Duration { } } -impl Mul for Duration { +impl Mul for Duration { + type Output = Duration; + fn mul(self, rhs: i32) -> Duration { // Multiply nanoseconds as i64, because it cannot overflow that way. let total_nanos = self.nanos as i64 * rhs as i64; @@ -307,7 +313,9 @@ impl Mul for Duration { } } -impl Div for Duration { +impl Div for Duration { + type Output = Duration; + fn div(self, rhs: i32) -> Duration { let mut secs = self.secs / rhs as i64; let carry = self.secs - secs * rhs as i64; -- cgit 1.4.1-3-g733a5