Skip to content

Commit 9e8a187

Browse files
author
Jorge Aparicio
committed
use assoc types in binop traits
1 parent c894171 commit 9e8a187

37 files changed

+376
-156
lines changed

src/libcollections/btree/set.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,9 @@ impl<T: Ord> Default for BTreeSet<T> {
462462
}
463463

464464
#[stable]
465-
impl<'a, 'b, T: Ord + Clone> Sub<&'b BTreeSet<T>, BTreeSet<T>> for &'a BTreeSet<T> {
465+
impl<'a, 'b, T: Ord + Clone> Sub<&'b BTreeSet<T>> for &'a BTreeSet<T> {
466+
type Output = BTreeSet<T>;
467+
466468
/// Returns the difference of `self` and `rhs` as a new `BTreeSet<T>`.
467469
///
468470
/// # Examples
@@ -483,7 +485,9 @@ impl<'a, 'b, T: Ord + Clone> Sub<&'b BTreeSet<T>, BTreeSet<T>> for &'a BTreeSet<
483485
}
484486

485487
#[stable]
486-
impl<'a, 'b, T: Ord + Clone> BitXor<&'b BTreeSet<T>, BTreeSet<T>> for &'a BTreeSet<T> {
488+
impl<'a, 'b, T: Ord + Clone> BitXor<&'b BTreeSet<T>> for &'a BTreeSet<T> {
489+
type Output = BTreeSet<T>;
490+
487491
/// Returns the symmetric difference of `self` and `rhs` as a new `BTreeSet<T>`.
488492
///
489493
/// # Examples
@@ -504,7 +508,9 @@ impl<'a, 'b, T: Ord + Clone> BitXor<&'b BTreeSet<T>, BTreeSet<T>> for &'a BTreeS
504508
}
505509

506510
#[stable]
507-
impl<'a, 'b, T: Ord + Clone> BitAnd<&'b BTreeSet<T>, BTreeSet<T>> for &'a BTreeSet<T> {
511+
impl<'a, 'b, T: Ord + Clone> BitAnd<&'b BTreeSet<T>> for &'a BTreeSet<T> {
512+
type Output = BTreeSet<T>;
513+
508514
/// Returns the intersection of `self` and `rhs` as a new `BTreeSet<T>`.
509515
///
510516
/// # Examples
@@ -525,7 +531,9 @@ impl<'a, 'b, T: Ord + Clone> BitAnd<&'b BTreeSet<T>, BTreeSet<T>> for &'a BTreeS
525531
}
526532

527533
#[stable]
528-
impl<'a, 'b, T: Ord + Clone> BitOr<&'b BTreeSet<T>, BTreeSet<T>> for &'a BTreeSet<T> {
534+
impl<'a, 'b, T: Ord + Clone> BitOr<&'b BTreeSet<T>> for &'a BTreeSet<T> {
535+
type Output = BTreeSet<T>;
536+
529537
/// Returns the union of `self` and `rhs` as a new `BTreeSet<T>`.
530538
///
531539
/// # Examples

src/libcollections/enum_set.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -185,25 +185,33 @@ impl<E:CLike> EnumSet<E> {
185185
}
186186
}
187187

188-
impl<E:CLike> Sub<EnumSet<E>, EnumSet<E>> for EnumSet<E> {
188+
impl<E:CLike> Sub for EnumSet<E> {
189+
type Output = EnumSet<E>;
190+
189191
fn sub(self, e: EnumSet<E>) -> EnumSet<E> {
190192
EnumSet {bits: self.bits & !e.bits}
191193
}
192194
}
193195

194-
impl<E:CLike> BitOr<EnumSet<E>, EnumSet<E>> for EnumSet<E> {
196+
impl<E:CLike> BitOr for EnumSet<E> {
197+
type Output = EnumSet<E>;
198+
195199
fn bitor(self, e: EnumSet<E>) -> EnumSet<E> {
196200
EnumSet {bits: self.bits | e.bits}
197201
}
198202
}
199203

200-
impl<E:CLike> BitAnd<EnumSet<E>, EnumSet<E>> for EnumSet<E> {
204+
impl<E:CLike> BitAnd for EnumSet<E> {
205+
type Output = EnumSet<E>;
206+
201207
fn bitand(self, e: EnumSet<E>) -> EnumSet<E> {
202208
EnumSet {bits: self.bits & e.bits}
203209
}
204210
}
205211

206-
impl<E:CLike> BitXor<EnumSet<E>, EnumSet<E>> for EnumSet<E> {
212+
impl<E:CLike> BitXor for EnumSet<E> {
213+
type Output = EnumSet<E>;
214+
207215
fn bitxor(self, e: EnumSet<E>) -> EnumSet<E> {
208216
EnumSet {bits: self.bits ^ e.bits}
209217
}

src/libcollections/string.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,9 @@ impl<'a, S: Str> Equiv<S> for String {
911911
}
912912

913913
#[experimental = "waiting on Add stabilization"]
914-
impl<'a> Add<&'a str, String> for String {
914+
impl<'a> Add<&'a str> for String {
915+
type Output = String;
916+
915917
fn add(mut self, other: &str) -> String {
916918
self.push_str(other);
917919
self

src/libcollections/vec.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1451,7 +1451,9 @@ impl<T> AsSlice<T> for Vec<T> {
14511451
}
14521452
}
14531453

1454-
impl<'a, T: Clone> Add<&'a [T], Vec<T>> for Vec<T> {
1454+
impl<'a, T: Clone> Add<&'a [T]> for Vec<T> {
1455+
type Output = Vec<T>;
1456+
14551457
#[inline]
14561458
fn add(mut self, rhs: &[T]) -> Vec<T> {
14571459
self.push_all(rhs);

src/libcore/iter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2355,7 +2355,7 @@ pub fn count<A>(start: A, step: A) -> Counter<A> {
23552355
}
23562356

23572357
#[unstable = "trait is unstable"]
2358-
impl<A: Add<A, A> + Clone> Iterator<A> for Counter<A> {
2358+
impl<A: Add<Output=A> + Clone> Iterator<A> for Counter<A> {
23592359
#[inline]
23602360
fn next(&mut self) -> Option<A> {
23612361
let result = self.state.clone();

src/libcore/num/mod.rs

+23-23
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use str::{FromStr, from_str, StrExt};
3535
/// Simultaneous division and remainder
3636
#[inline]
3737
#[deprecated = "use division and remainder directly"]
38-
pub fn div_rem<T: Clone + Div<T, T> + Rem<T, T>>(x: T, y: T) -> (T, T) {
38+
pub fn div_rem<T: Clone + Div<Output=T> + Rem<Output=T>>(x: T, y: T) -> (T, T) {
3939
(x.clone() / y.clone(), x % y)
4040
}
4141

@@ -53,17 +53,17 @@ pub trait Int
5353
+ NumCast
5454
+ PartialOrd + Ord
5555
+ PartialEq + Eq
56-
+ Add<Self,Self>
57-
+ Sub<Self,Self>
58-
+ Mul<Self,Self>
59-
+ Div<Self,Self>
60-
+ Rem<Self,Self>
56+
+ Add<Output=Self>
57+
+ Sub<Output=Self>
58+
+ Mul<Output=Self>
59+
+ Div<Output=Self>
60+
+ Rem<Output=Self>
6161
+ Not<Self>
62-
+ BitAnd<Self,Self>
63-
+ BitOr<Self,Self>
64-
+ BitXor<Self,Self>
65-
+ Shl<uint,Self>
66-
+ Shr<uint,Self>
62+
+ BitAnd<Output=Self>
63+
+ BitOr<Output=Self>
64+
+ BitXor<Output=Self>
65+
+ Shl<uint, Output=Self>
66+
+ Shr<uint, Output=Self>
6767
{
6868
/// Returns the `0` value of this integer type.
6969
// FIXME (#5527): Should be an associated constant
@@ -1246,11 +1246,11 @@ pub trait Float
12461246
+ PartialOrd
12471247
+ PartialEq
12481248
+ Neg<Self>
1249-
+ Add<Self,Self>
1250-
+ Sub<Self,Self>
1251-
+ Mul<Self,Self>
1252-
+ Div<Self,Self>
1253-
+ Rem<Self,Self>
1249+
+ Add<Output=Self>
1250+
+ Sub<Output=Self>
1251+
+ Mul<Output=Self>
1252+
+ Div<Output=Self>
1253+
+ Rem<Output=Self>
12541254
{
12551255
/// Returns the NaN value.
12561256
fn nan() -> Self;
@@ -1719,11 +1719,11 @@ macro_rules! trait_impl {
17191719
#[allow(deprecated)]
17201720
pub trait Num: PartialEq + Zero + One
17211721
+ Neg<Self>
1722-
+ Add<Self,Self>
1723-
+ Sub<Self,Self>
1724-
+ Mul<Self,Self>
1725-
+ Div<Self,Self>
1726-
+ Rem<Self,Self> {}
1722+
+ Add<Output=Self>
1723+
+ Sub<Output=Self>
1724+
+ Mul<Output=Self>
1725+
+ Div<Output=Self>
1726+
+ Rem<Output=Self> {}
17271727
trait_impl! { Num for uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 }
17281728

17291729
#[deprecated = "Generalised unsigned numbers are no longer supported"]
@@ -1737,7 +1737,7 @@ pub trait Primitive: Copy + Clone + Num + NumCast + PartialOrd {}
17371737
trait_impl! { Primitive for uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 }
17381738

17391739
#[deprecated = "The generic `Zero` trait will be removed soon."]
1740-
pub trait Zero: Add<Self, Self> {
1740+
pub trait Zero: Add<Output=Self> {
17411741
#[deprecated = "Use `Int::zero()` or `Float::zero()`."]
17421742
fn zero() -> Self;
17431743
#[deprecated = "Use `x == Int::zero()` or `x == Float::zero()`."]
@@ -1768,7 +1768,7 @@ zero_impl! { f32, 0.0f32 }
17681768
zero_impl! { f64, 0.0f64 }
17691769

17701770
#[deprecated = "The generic `One` trait will be removed soon."]
1771-
pub trait One: Mul<Self, Self> {
1771+
pub trait One: Mul<Output=Self> {
17721772
#[deprecated = "Use `Int::one()` or `Float::one()`."]
17731773
fn one() -> Self;
17741774
}

0 commit comments

Comments
 (0)