Skip to content

Commit dbd1383

Browse files
author
Jorge Aparicio
committed
use assoc types in binop traits
1 parent 39d7402 commit dbd1383

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+372
-153
lines changed

src/libcollections/btree/set.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,9 @@ impl<T: Ord> Default for BTreeSet<T> {
449449
}
450450

451451
#[unstable = "matches collection reform specification, waiting for dust to settle"]
452-
impl<'a, 'b, T: Ord + Clone> Sub<&'b BTreeSet<T>, BTreeSet<T>> for &'a BTreeSet<T> {
452+
impl<'a, 'b, T: Ord + Clone> Sub<&'b BTreeSet<T>> for &'a BTreeSet<T> {
453+
type Output = BTreeSet<T>;
454+
453455
/// Returns the difference of `self` and `rhs` as a new `BTreeSet<T>`.
454456
///
455457
/// # Examples
@@ -470,7 +472,9 @@ impl<'a, 'b, T: Ord + Clone> Sub<&'b BTreeSet<T>, BTreeSet<T>> for &'a BTreeSet<
470472
}
471473

472474
#[unstable = "matches collection reform specification, waiting for dust to settle"]
473-
impl<'a, 'b, T: Ord + Clone> BitXor<&'b BTreeSet<T>, BTreeSet<T>> for &'a BTreeSet<T> {
475+
impl<'a, 'b, T: Ord + Clone> BitXor<&'b BTreeSet<T>> for &'a BTreeSet<T> {
476+
type Output = BTreeSet<T>;
477+
474478
/// Returns the symmetric difference of `self` and `rhs` as a new `BTreeSet<T>`.
475479
///
476480
/// # Examples
@@ -491,7 +495,9 @@ impl<'a, 'b, T: Ord + Clone> BitXor<&'b BTreeSet<T>, BTreeSet<T>> for &'a BTreeS
491495
}
492496

493497
#[unstable = "matches collection reform specification, waiting for dust to settle"]
494-
impl<'a, 'b, T: Ord + Clone> BitAnd<&'b BTreeSet<T>, BTreeSet<T>> for &'a BTreeSet<T> {
498+
impl<'a, 'b, T: Ord + Clone> BitAnd<&'b BTreeSet<T>> for &'a BTreeSet<T> {
499+
type Output = BTreeSet<T>;
500+
495501
/// Returns the intersection of `self` and `rhs` as a new `BTreeSet<T>`.
496502
///
497503
/// # Examples
@@ -512,7 +518,9 @@ impl<'a, 'b, T: Ord + Clone> BitAnd<&'b BTreeSet<T>, BTreeSet<T>> for &'a BTreeS
512518
}
513519

514520
#[unstable = "matches collection reform specification, waiting for dust to settle"]
515-
impl<'a, 'b, T: Ord + Clone> BitOr<&'b BTreeSet<T>, BTreeSet<T>> for &'a BTreeSet<T> {
521+
impl<'a, 'b, T: Ord + Clone> BitOr<&'b BTreeSet<T>> for &'a BTreeSet<T> {
522+
type Output = BTreeSet<T>;
523+
516524
/// Returns the union of `self` and `rhs` as a new `BTreeSet<T>`.
517525
///
518526
/// # Examples

src/libcollections/enum_set.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,25 +183,33 @@ impl<E:CLike> EnumSet<E> {
183183
}
184184
}
185185

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

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

198-
impl<E:CLike> BitAnd<EnumSet<E>, EnumSet<E>> for EnumSet<E> {
202+
impl<E:CLike> BitAnd for EnumSet<E> {
203+
type Output = EnumSet<E>;
204+
199205
fn bitand(self, e: EnumSet<E>) -> EnumSet<E> {
200206
EnumSet {bits: self.bits & e.bits}
201207
}
202208
}
203209

204-
impl<E:CLike> BitXor<EnumSet<E>, EnumSet<E>> for EnumSet<E> {
210+
impl<E:CLike> BitXor for EnumSet<E> {
211+
type Output = EnumSet<E>;
212+
205213
fn bitxor(self, e: EnumSet<E>) -> EnumSet<E> {
206214
EnumSet {bits: self.bits ^ e.bits}
207215
}

src/libcollections/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#![feature(macro_rules, default_type_params, phase, globs)]
2626
#![feature(unsafe_destructor, slicing_syntax)]
2727
#![feature(unboxed_closures)]
28+
#![feature(associated_types)]
2829
#![no_std]
2930

3031
#[phase(plugin, link)] extern crate core;

src/libcollections/string.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,9 @@ impl<'a, S: Str> Equiv<S> for String {
906906
}
907907

908908
#[experimental = "waiting on Add stabilization"]
909-
impl<'a> Add<&'a str, String> for String {
909+
impl<'a> Add<&'a str> for String {
910+
type Output = String;
911+
910912
fn add(mut self, other: &str) -> String {
911913
self.push_str(other);
912914
self

src/libcollections/vec.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1449,7 +1449,9 @@ impl<T> AsSlice<T> for Vec<T> {
14491449
}
14501450
}
14511451

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

src/libcore/iter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2354,7 +2354,7 @@ pub fn count<A>(start: A, step: A) -> Counter<A> {
23542354
}
23552355

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

src/libcore/num/mod.rs

Lines changed: 23 additions & 23 deletions
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)