Skip to content

Use associated types in unop and binop traits #20474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/libcollections/btree/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,9 @@ impl<T: Ord> Default for BTreeSet<T> {
}

#[stable]
impl<'a, 'b, T: Ord + Clone> Sub<&'b BTreeSet<T>, BTreeSet<T>> for &'a BTreeSet<T> {
impl<'a, 'b, T: Ord + Clone> Sub<&'b BTreeSet<T>> for &'a BTreeSet<T> {
type Output = BTreeSet<T>;

/// Returns the difference of `self` and `rhs` as a new `BTreeSet<T>`.
///
/// # Examples
Expand All @@ -483,7 +485,9 @@ impl<'a, 'b, T: Ord + Clone> Sub<&'b BTreeSet<T>, BTreeSet<T>> for &'a BTreeSet<
}

#[stable]
impl<'a, 'b, T: Ord + Clone> BitXor<&'b BTreeSet<T>, BTreeSet<T>> for &'a BTreeSet<T> {
impl<'a, 'b, T: Ord + Clone> BitXor<&'b BTreeSet<T>> for &'a BTreeSet<T> {
type Output = BTreeSet<T>;

/// Returns the symmetric difference of `self` and `rhs` as a new `BTreeSet<T>`.
///
/// # Examples
Expand All @@ -504,7 +508,9 @@ impl<'a, 'b, T: Ord + Clone> BitXor<&'b BTreeSet<T>, BTreeSet<T>> for &'a BTreeS
}

#[stable]
impl<'a, 'b, T: Ord + Clone> BitAnd<&'b BTreeSet<T>, BTreeSet<T>> for &'a BTreeSet<T> {
impl<'a, 'b, T: Ord + Clone> BitAnd<&'b BTreeSet<T>> for &'a BTreeSet<T> {
type Output = BTreeSet<T>;

/// Returns the intersection of `self` and `rhs` as a new `BTreeSet<T>`.
///
/// # Examples
Expand All @@ -525,7 +531,9 @@ impl<'a, 'b, T: Ord + Clone> BitAnd<&'b BTreeSet<T>, BTreeSet<T>> for &'a BTreeS
}

#[stable]
impl<'a, 'b, T: Ord + Clone> BitOr<&'b BTreeSet<T>, BTreeSet<T>> for &'a BTreeSet<T> {
impl<'a, 'b, T: Ord + Clone> BitOr<&'b BTreeSet<T>> for &'a BTreeSet<T> {
type Output = BTreeSet<T>;

/// Returns the union of `self` and `rhs` as a new `BTreeSet<T>`.
///
/// # Examples
Expand Down
16 changes: 12 additions & 4 deletions src/libcollections/enum_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,25 +185,33 @@ impl<E:CLike> EnumSet<E> {
}
}

impl<E:CLike> Sub<EnumSet<E>, EnumSet<E>> for EnumSet<E> {
impl<E:CLike> Sub for EnumSet<E> {
type Output = EnumSet<E>;

fn sub(self, e: EnumSet<E>) -> EnumSet<E> {
EnumSet {bits: self.bits & !e.bits}
}
}

impl<E:CLike> BitOr<EnumSet<E>, EnumSet<E>> for EnumSet<E> {
impl<E:CLike> BitOr for EnumSet<E> {
type Output = EnumSet<E>;

fn bitor(self, e: EnumSet<E>) -> EnumSet<E> {
EnumSet {bits: self.bits | e.bits}
}
}

impl<E:CLike> BitAnd<EnumSet<E>, EnumSet<E>> for EnumSet<E> {
impl<E:CLike> BitAnd for EnumSet<E> {
type Output = EnumSet<E>;

fn bitand(self, e: EnumSet<E>) -> EnumSet<E> {
EnumSet {bits: self.bits & e.bits}
}
}

impl<E:CLike> BitXor<EnumSet<E>, EnumSet<E>> for EnumSet<E> {
impl<E:CLike> BitXor for EnumSet<E> {
type Output = EnumSet<E>;

fn bitxor(self, e: EnumSet<E>) -> EnumSet<E> {
EnumSet {bits: self.bits ^ e.bits}
}
Expand Down
4 changes: 3 additions & 1 deletion src/libcollections/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,9 @@ impl<'a, S: Str> Equiv<S> for String {
}

#[experimental = "waiting on Add stabilization"]
impl<'a> Add<&'a str, String> for String {
impl<'a> Add<&'a str> for String {
type Output = String;

fn add(mut self, other: &str) -> String {
self.push_str(other);
self
Expand Down
4 changes: 3 additions & 1 deletion src/libcollections/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1451,7 +1451,9 @@ impl<T> AsSlice<T> for Vec<T> {
}
}

impl<'a, T: Clone> Add<&'a [T], Vec<T>> for Vec<T> {
impl<'a, T: Clone> Add<&'a [T]> for Vec<T> {
type Output = Vec<T>;

#[inline]
fn add(mut self, rhs: &[T]) -> Vec<T> {
self.push_all(rhs);
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2355,7 +2355,7 @@ pub fn count<A>(start: A, step: A) -> Counter<A> {
}

#[unstable = "trait is unstable"]
impl<A: Add<A, A> + Clone> Iterator<A> for Counter<A> {
impl<A: Add<Output=A> + Clone> Iterator<A> for Counter<A> {
#[inline]
fn next(&mut self) -> Option<A> {
let result = self.state.clone();
Expand Down
54 changes: 27 additions & 27 deletions src/libcore/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use str::{FromStr, from_str, StrExt};
/// Simultaneous division and remainder
#[inline]
#[deprecated = "use division and remainder directly"]
pub fn div_rem<T: Clone + Div<T, T> + Rem<T, T>>(x: T, y: T) -> (T, T) {
pub fn div_rem<T: Clone + Div<Output=T> + Rem<Output=T>>(x: T, y: T) -> (T, T) {
(x.clone() / y.clone(), x % y)
}

Expand All @@ -53,17 +53,17 @@ pub trait Int
+ NumCast
+ PartialOrd + Ord
+ PartialEq + Eq
+ Add<Self,Self>
+ Sub<Self,Self>
+ Mul<Self,Self>
+ Div<Self,Self>
+ Rem<Self,Self>
+ Not<Self>
+ BitAnd<Self,Self>
+ BitOr<Self,Self>
+ BitXor<Self,Self>
+ Shl<uint,Self>
+ Shr<uint,Self>
+ Add<Output=Self>
+ Sub<Output=Self>
+ Mul<Output=Self>
+ Div<Output=Self>
+ Rem<Output=Self>
+ Not<Output=Self>
+ BitAnd<Output=Self>
+ BitOr<Output=Self>
+ BitXor<Output=Self>
+ Shl<uint, Output=Self>
+ Shr<uint, Output=Self>
{
/// Returns the `0` value of this integer type.
// FIXME (#5527): Should be an associated constant
Expand Down Expand Up @@ -613,7 +613,7 @@ int_impl! { int = i64, u64, 64,
#[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()`.
Expand Down Expand Up @@ -1245,12 +1245,12 @@ pub trait Float
+ NumCast
+ PartialOrd
+ PartialEq
+ Neg<Self>
+ Add<Self,Self>
+ Sub<Self,Self>
+ Mul<Self,Self>
+ Div<Self,Self>
+ Rem<Self,Self>
+ Neg<Output=Self>
+ Add<Output=Self>
+ Sub<Output=Self>
+ Mul<Output=Self>
+ Div<Output=Self>
+ Rem<Output=Self>
{
/// Returns the NaN value.
fn nan() -> Self;
Expand Down Expand Up @@ -1718,12 +1718,12 @@ macro_rules! trait_impl {
#[deprecated = "Generalised numbers are no longer supported"]
#[allow(deprecated)]
pub trait Num: PartialEq + Zero + One
+ Neg<Self>
+ Add<Self,Self>
+ Sub<Self,Self>
+ Mul<Self,Self>
+ Div<Self,Self>
+ Rem<Self,Self> {}
+ Neg<Output=Self>
+ Add<Output=Self>
+ Sub<Output=Self>
+ Mul<Output=Self>
+ Div<Output=Self>
+ Rem<Output=Self> {}
trait_impl! { Num for uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 }

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

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

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