}
#[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
}
#[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
}
#[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
}
#[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
}
}
-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}
}
}
#[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
}
}
-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);
}
#[unstable = "trait is unstable"]
-impl<A: Add<A, A> + Clone> Iterator for Counter<A> {
+impl<A: Add<Output=A> + Clone> Iterator for Counter<A> {
type Item = A;
#[inline]
/// 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)
}
+ NumCast
+ PartialOrd + Ord
+ PartialEq + Eq
- + Add<Self,Self>
- + Sub<Self,Self>
- + Mul<Self,Self>
- + Div<Self,Self>
- + Rem<Self,Self>
+ + Add<Output=Self>
+ + Sub<Output=Self>
+ + Mul<Output=Self>
+ + Div<Output=Self>
+ + Rem<Output=Self>
+ Not<Self>
- + BitAnd<Self,Self>
- + BitOr<Self,Self>
- + BitXor<Self,Self>
- + Shl<uint,Self>
- + Shr<uint,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
+ PartialOrd
+ PartialEq
+ Neg<Self>
- + Add<Self,Self>
- + Sub<Self,Self>
- + Mul<Self,Self>
- + Div<Self,Self>
- + Rem<Self,Self>
+ + Add<Output=Self>
+ + Sub<Output=Self>
+ + Mul<Output=Self>
+ + Div<Output=Self>
+ + Rem<Output=Self>
{
/// Returns the NaN value.
fn nan() -> Self;
#[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> {}
+ + 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"]
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()`."]
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;
}
//! demonstrates adding and subtracting two `Point`s.
//!
//! ```rust
+//! #![feature(associated_types)]
+//!
//! use std::ops::{Add, Sub};
//!
//! #[deriving(Show)]
//! y: int
//! }
//!
-//! impl Add<Point, Point> for Point {
+//! impl Add for Point {
+//! type Output = Point;
+//!
//! fn add(self, other: Point) -> Point {
//! Point {x: self.x + other.x, y: self.y + other.y}
//! }
//! }
//!
-//! impl Sub<Point, Point> for Point {
+//! impl Sub for Point {
+//! type Output = Point;
+//!
//! fn sub(self, other: Point) -> Point {
//! Point {x: self.x - other.x, y: self.y - other.y}
//! }
/// calling `add`, and therefore, `main` prints `Adding!`.
///
/// ```rust
+/// #![feature(associated_types)]
+///
/// use std::ops::Add;
///
/// #[deriving(Copy)]
/// struct Foo;
///
-/// impl Add<Foo, Foo> for Foo {
+/// impl Add for Foo {
+/// type Output = Foo;
+///
/// fn add(self, _rhs: Foo) -> Foo {
/// println!("Adding!");
/// self
/// }
/// ```
#[lang="add"]
-pub trait Add<RHS, Result> {
+pub trait Add<RHS=Self> {
+ type Output;
+
/// The method for the `+` operator
- fn add(self, rhs: RHS) -> Result;
+ fn add(self, rhs: RHS) -> Self::Output;
}
macro_rules! add_impl {
($($t:ty)*) => ($(
- impl Add<$t, $t> for $t {
+ impl Add for $t {
+ type Output = $t;
+
#[inline]
fn add(self, other: $t) -> $t { self + other }
}
/// calling `sub`, and therefore, `main` prints `Subtracting!`.
///
/// ```rust
+/// #![feature(associated_types)]
+///
/// use std::ops::Sub;
///
/// #[deriving(Copy)]
/// struct Foo;
///
-/// impl Sub<Foo, Foo> for Foo {
+/// impl Sub for Foo {
+/// type Output = Foo;
+///
/// fn sub(self, _rhs: Foo) -> Foo {
/// println!("Subtracting!");
/// self
/// }
/// ```
#[lang="sub"]
-pub trait Sub<RHS, Result> {
+pub trait Sub<RHS=Self> {
+ type Output;
+
/// The method for the `-` operator
- fn sub(self, rhs: RHS) -> Result;
+ fn sub(self, rhs: RHS) -> Self::Output;
}
macro_rules! sub_impl {
($($t:ty)*) => ($(
- impl Sub<$t, $t> for $t {
+ impl Sub for $t {
+ type Output = $t;
+
#[inline]
fn sub(self, other: $t) -> $t { self - other }
}
/// calling `mul`, and therefore, `main` prints `Multiplying!`.
///
/// ```rust
+/// #![feature(associated_types)]
+///
/// use std::ops::Mul;
///
/// #[deriving(Copy)]
/// struct Foo;
///
-/// impl Mul<Foo, Foo> for Foo {
+/// impl Mul for Foo {
+/// type Output = Foo;
+///
/// fn mul(self, _rhs: Foo) -> Foo {
/// println!("Multiplying!");
/// self
/// }
/// ```
#[lang="mul"]
-pub trait Mul<RHS, Result> {
+pub trait Mul<RHS=Self> {
+ type Output;
+
/// The method for the `*` operator
- fn mul(self, rhs: RHS) -> Result;
+ fn mul(self, rhs: RHS) -> Self::Output;
}
macro_rules! mul_impl {
($($t:ty)*) => ($(
- impl Mul<$t, $t> for $t {
+ impl Mul for $t {
+ type Output = $t;
+
#[inline]
fn mul(self, other: $t) -> $t { self * other }
}
/// calling `div`, and therefore, `main` prints `Dividing!`.
///
/// ```
+/// #![feature(associated_types)]
+///
/// use std::ops::Div;
///
/// #[deriving(Copy)]
/// struct Foo;
///
-/// impl Div<Foo, Foo> for Foo {
+/// impl Div for Foo {
+/// type Output = Foo;
+///
/// fn div(self, _rhs: Foo) -> Foo {
/// println!("Dividing!");
/// self
/// }
/// ```
#[lang="div"]
-pub trait Div<RHS, Result> {
+pub trait Div<RHS=Self> {
+ type Output;
+
/// The method for the `/` operator
- fn div(self, rhs: RHS) -> Result;
+ fn div(self, rhs: RHS) -> Self::Output;
}
macro_rules! div_impl {
($($t:ty)*) => ($(
- impl Div<$t, $t> for $t {
+ impl Div for $t {
+ type Output = $t;
+
#[inline]
fn div(self, other: $t) -> $t { self / other }
}
/// calling `rem`, and therefore, `main` prints `Remainder-ing!`.
///
/// ```
+/// #![feature(associated_types)]
+///
/// use std::ops::Rem;
///
/// #[deriving(Copy)]
/// struct Foo;
///
-/// impl Rem<Foo, Foo> for Foo {
+/// impl Rem for Foo {
+/// type Output = Foo;
+///
/// fn rem(self, _rhs: Foo) -> Foo {
/// println!("Remainder-ing!");
/// self
/// }
/// ```
#[lang="rem"]
-pub trait Rem<RHS, Result> {
+pub trait Rem<RHS=Self> {
+ type Output = Self;
+
/// The method for the `%` operator
- fn rem(self, rhs: RHS) -> Result;
+ fn rem(self, rhs: RHS) -> Self::Output;
}
macro_rules! rem_impl {
($($t:ty)*) => ($(
- impl Rem<$t, $t> for $t {
+ impl Rem for $t {
+ type Output = $t;
+
#[inline]
fn rem(self, other: $t) -> $t { self % other }
}
macro_rules! rem_float_impl {
($t:ty, $fmod:ident) => {
- impl Rem<$t, $t> for $t {
+ impl Rem for $t {
+ type Output = $t;
+
#[inline]
fn rem(self, other: $t) -> $t {
extern { fn $fmod(a: $t, b: $t) -> $t; }
/// calling `bitand`, and therefore, `main` prints `Bitwise And-ing!`.
///
/// ```
+/// #![feature(associated_types)]
+///
/// use std::ops::BitAnd;
///
/// #[deriving(Copy)]
/// struct Foo;
///
-/// impl BitAnd<Foo, Foo> for Foo {
+/// impl BitAnd for Foo {
+/// type Output = Foo;
+///
/// fn bitand(self, _rhs: Foo) -> Foo {
/// println!("Bitwise And-ing!");
/// self
/// }
/// ```
#[lang="bitand"]
-pub trait BitAnd<RHS, Result> {
+pub trait BitAnd<RHS=Self> {
+ type Output;
+
/// The method for the `&` operator
- fn bitand(self, rhs: RHS) -> Result;
+ fn bitand(self, rhs: RHS) -> Self::Output;
}
macro_rules! bitand_impl {
($($t:ty)*) => ($(
- impl BitAnd<$t, $t> for $t {
+ impl BitAnd for $t {
+ type Output = $t;
+
#[inline]
fn bitand(self, rhs: $t) -> $t { self & rhs }
}
/// calling `bitor`, and therefore, `main` prints `Bitwise Or-ing!`.
///
/// ```
+/// #![feature(associated_types)]
+///
/// use std::ops::BitOr;
///
/// #[deriving(Copy)]
/// struct Foo;
///
-/// impl BitOr<Foo, Foo> for Foo {
+/// impl BitOr for Foo {
+/// type Output = Foo;
+///
/// fn bitor(self, _rhs: Foo) -> Foo {
/// println!("Bitwise Or-ing!");
/// self
/// }
/// ```
#[lang="bitor"]
-pub trait BitOr<RHS, Result> {
+pub trait BitOr<RHS=Self> {
+ type Output;
+
/// The method for the `|` operator
- fn bitor(self, rhs: RHS) -> Result;
+ fn bitor(self, rhs: RHS) -> Self::Output;
}
macro_rules! bitor_impl {
($($t:ty)*) => ($(
- impl BitOr<$t,$t> for $t {
+ impl BitOr for $t {
+ type Output = $t;
+
#[inline]
fn bitor(self, rhs: $t) -> $t { self | rhs }
}
/// calling `bitxor`, and therefore, `main` prints `Bitwise Xor-ing!`.
///
/// ```
+/// #![feature(associated_types)]
+///
/// use std::ops::BitXor;
///
/// #[deriving(Copy)]
/// struct Foo;
///
-/// impl BitXor<Foo, Foo> for Foo {
+/// impl BitXor for Foo {
+/// type Output = Foo;
+///
/// fn bitxor(self, _rhs: Foo) -> Foo {
/// println!("Bitwise Xor-ing!");
/// self
/// }
/// ```
#[lang="bitxor"]
-pub trait BitXor<RHS, Result> {
+pub trait BitXor<RHS=Self> {
+ type Output;
+
/// The method for the `^` operator
- fn bitxor(self, rhs: RHS) -> Result;
+ fn bitxor(self, rhs: RHS) -> Self::Output;
}
macro_rules! bitxor_impl {
($($t:ty)*) => ($(
- impl BitXor<$t, $t> for $t {
+ impl BitXor for $t {
+ type Output = $t;
+
#[inline]
fn bitxor(self, other: $t) -> $t { self ^ other }
}
/// calling `shl`, and therefore, `main` prints `Shifting left!`.
///
/// ```
+/// #![feature(associated_types)]
+///
/// use std::ops::Shl;
///
/// #[deriving(Copy)]
/// struct Foo;
///
-/// impl Shl<Foo, Foo> for Foo {
+/// impl Shl<Foo> for Foo {
+/// type Output = Foo;
+///
/// fn shl(self, _rhs: Foo) -> Foo {
/// println!("Shifting left!");
/// self
/// }
/// ```
#[lang="shl"]
-pub trait Shl<RHS, Result> {
+pub trait Shl<RHS> {
+ type Output;
+
/// The method for the `<<` operator
- fn shl(self, rhs: RHS) -> Result;
+ fn shl(self, rhs: RHS) -> Self::Output;
}
macro_rules! shl_impl {
($($t:ty)*) => ($(
- impl Shl<uint, $t> for $t {
+ impl Shl<uint> for $t {
+ type Output = $t;
+
#[inline]
fn shl(self, other: uint) -> $t {
self << other
/// calling `shr`, and therefore, `main` prints `Shifting right!`.
///
/// ```
+/// #![feature(associated_types)]
+///
/// use std::ops::Shr;
///
/// #[deriving(Copy)]
/// struct Foo;
///
-/// impl Shr<Foo, Foo> for Foo {
+/// impl Shr<Foo> for Foo {
+/// type Output = Foo;
+///
/// fn shr(self, _rhs: Foo) -> Foo {
/// println!("Shifting right!");
/// self
/// }
/// ```
#[lang="shr"]
-pub trait Shr<RHS, Result> {
+pub trait Shr<RHS> {
+ type Output;
+
/// The method for the `>>` operator
- fn shr(self, rhs: RHS) -> Result;
+ fn shr(self, rhs: RHS) -> Self::Output;
}
macro_rules! shr_impl {
($($t:ty)*) => ($(
- impl Shr<uint, $t> for $t {
+ impl Shr<uint> for $t {
+ type Output = $t;
+
#[inline]
fn shr(self, other: uint) -> $t { self >> other }
}
/// Helper function for testing numeric operations
pub fn test_num<T>(ten: T, two: T) where
T: PartialEq + NumCast
- + Add<T, T> + Sub<T, T>
- + Mul<T, T> + Div<T, T>
- + Rem<T, T> + Show
+ + Add<Output=T> + Sub<Output=T>
+ + Mul<Output=T> + Div<Output=T>
+ + Rem<Output=T> + Show
+ Copy
{
assert_eq!(ten.add(two), cast(12i).unwrap());
}
}
-impl ops::BitOr<TypeContents,TypeContents> for TypeContents {
+impl ops::BitOr for TypeContents {
+ type Output = TypeContents;
+
fn bitor(self, other: TypeContents) -> TypeContents {
TypeContents {bits: self.bits | other.bits}
}
}
-impl ops::BitAnd<TypeContents, TypeContents> for TypeContents {
+impl ops::BitAnd for TypeContents {
+ type Output = TypeContents;
+
fn bitand(self, other: TypeContents) -> TypeContents {
TypeContents {bits: self.bits & other.bits}
}
}
-impl ops::Sub<TypeContents, TypeContents> for TypeContents {
+impl ops::Sub for TypeContents {
+ type Output = TypeContents;
+
fn sub(self, other: TypeContents) -> TypeContents {
TypeContents {bits: self.bits & !other.bits}
}
#![feature(globs, macro_rules, phase, slicing_syntax)]
#![feature(unboxed_closures)]
#![feature(old_orphan_check)]
+#![feature(associated_types)]
extern crate arena;
extern crate getopts;
pub unmarked: uint,
}
-impl Add<Counts, Counts> for Counts {
+impl Add for Counts {
+ type Output = Counts;
+
fn add(self, other: Counts) -> Counts {
Counts {
deprecated: self.deprecated + other.deprecated,
}
}
- 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 {
}
}
- 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 {
}
}
- 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 {
}
}
- 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 {
#[stable]
impl<'a, 'b, T: Eq + Hash<S> + Clone, S, H: Hasher<S> + Default>
-BitOr<&'b HashSet<T, H>, HashSet<T, H>> for &'a HashSet<T, H> {
+BitOr<&'b HashSet<T, H>> for &'a HashSet<T, H> {
+ type Output = HashSet<T, H>;
+
/// Returns the union of `self` and `rhs` as a new `HashSet<T, H>`.
///
/// # Examples
#[stable]
impl<'a, 'b, T: Eq + Hash<S> + Clone, S, H: Hasher<S> + Default>
-BitAnd<&'b HashSet<T, H>, HashSet<T, H>> for &'a HashSet<T, H> {
+BitAnd<&'b HashSet<T, H>> for &'a HashSet<T, H> {
+ type Output = HashSet<T, H>;
+
/// Returns the intersection of `self` and `rhs` as a new `HashSet<T, H>`.
///
/// # Examples
#[stable]
impl<'a, 'b, T: Eq + Hash<S> + Clone, S, H: Hasher<S> + Default>
-BitXor<&'b HashSet<T, H>, HashSet<T, H>> for &'a HashSet<T, H> {
+BitXor<&'b HashSet<T, H>> for &'a HashSet<T, H> {
+ type Output = HashSet<T, H>;
+
/// Returns the symmetric difference of `self` and `rhs` as a new `HashSet<T, H>`.
///
/// # Examples
#[stable]
impl<'a, 'b, T: Eq + Hash<S> + Clone, S, H: Hasher<S> + Default>
-Sub<&'b HashSet<T, H>, HashSet<T, H>> for &'a HashSet<T, H> {
+Sub<&'b HashSet<T, H>> for &'a HashSet<T, H> {
+ type Output = HashSet<T, H>;
+
/// Returns the difference of `self` and `rhs` as a new `HashSet<T, H>`.
///
/// # Examples
#[cfg(test)]
pub fn test_num<T>(ten: T, two: T) where
T: PartialEq + NumCast
- + Add<T, T> + Sub<T, T>
- + Mul<T, T> + Div<T, T>
- + Rem<T, T> + Show
+ + Add<Output=T> + Sub<Output=T>
+ + Mul<Output=T> + Div<Output=T>
+ + Rem<Output=T> + Show
+ Copy
{
assert_eq!(ten.add(two), cast(12i).unwrap());
}
}
-impl Add<Duration, Duration> 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;
}
}
-impl Sub<Duration, Duration> 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;
}
}
-impl Mul<i32, Duration> for Duration {
+impl Mul<i32> 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;
}
}
-impl Div<i32, Duration> for Duration {
+impl Div<i32> 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;
fn to_uint(&self) -> uint { let BytePos(n) = *self; n as uint }
}
-impl Add<BytePos, BytePos> for BytePos {
+impl Add for BytePos {
+ type Output = BytePos;
+
fn add(self, rhs: BytePos) -> BytePos {
BytePos((self.to_uint() + rhs.to_uint()) as u32)
}
}
-impl Sub<BytePos, BytePos> for BytePos {
+impl Sub for BytePos {
+ type Output = BytePos;
+
fn sub(self, rhs: BytePos) -> BytePos {
BytePos((self.to_uint() - rhs.to_uint()) as u32)
}
fn to_uint(&self) -> uint { let CharPos(n) = *self; n }
}
-impl Add<CharPos, CharPos> for CharPos {
+impl Add for CharPos {
+ type Output = CharPos;
+
fn add(self, rhs: CharPos) -> CharPos {
CharPos(self.to_uint() + rhs.to_uint())
}
}
-impl Sub<CharPos, CharPos> for CharPos {
+impl Sub for CharPos {
+ type Output = CharPos;
+
fn sub(self, rhs: CharPos) -> CharPos {
CharPos(self.to_uint() - rhs.to_uint())
}
LisContradiction(String),
}
-impl Add<LockstepIterSize, LockstepIterSize> for LockstepIterSize {
+impl Add for LockstepIterSize {
+ type Output = LockstepIterSize;
+
fn add(self, other: LockstepIterSize) -> LockstepIterSize {
match self {
LisUnconstrained => other,
#![allow(unknown_features)]
#![feature(phase, globs)]
#![feature(old_orphan_check)]
+#![feature(associated_types)]
+#![feature(default_type_params)]
#[cfg(test)] #[phase(plugin, link)] extern crate log;
}
}
-impl Add<Duration, Timespec> for Timespec {
+impl Add<Duration> for Timespec {
+ type Output = Timespec;
+
fn add(self, other: Duration) -> Timespec {
let d_sec = other.num_seconds();
// It is safe to unwrap the nanoseconds, because there cannot be
}
}
-impl Sub<Timespec, Duration> for Timespec {
+impl Sub for Timespec {
+ type Output = Duration;
+
fn sub(self, other: Timespec) -> Duration {
let sec = self.sec - other.sec;
let nsec = self.nsec - other.nsec;
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+#![feature(associated_types)]
+
use std::cmp::PartialEq;
use std::ops::{Add, Sub, Mul};
-pub trait MyNum : Add<Self,Self> + Sub<Self,Self> + Mul<Self,Self> + PartialEq + Clone {
+pub trait MyNum : Add<Output=Self> + Sub<Output=Self> + Mul<Output=Self> + PartialEq + Clone {
}
#[derive(Clone, Show)]
pub val: int
}
-impl Add<MyInt, MyInt> for MyInt {
+impl Add for MyInt {
+ type Output = MyInt;
+
fn add(self, other: MyInt) -> MyInt { mi(self.val + other.val) }
}
-impl Sub<MyInt, MyInt> for MyInt {
+impl Sub for MyInt {
+ type Output = MyInt;
+
fn sub(self, other: MyInt) -> MyInt { mi(self.val - other.val) }
}
-impl Mul<MyInt, MyInt> for MyInt {
+impl Mul for MyInt {
+ type Output = MyInt;
+
fn mul(self, other: MyInt) -> MyInt { mi(self.val * other.val) }
}
f() + g()
}
-pub fn has_generic_closures<T: Add<T,T> + Copy>(x: T, y: T) -> T {
+pub fn has_generic_closures<T: Add<Output=T> + Copy>(x: T, y: T) -> T {
let mut f = move |&mut:| x;
let g = |:| y;
f() + g()
// Test that binary operators consume their arguments
+#![feature(associated_types, default_type_params)]
+
use std::ops::{Add, Sub, Mul, Div, Rem, BitAnd, BitXor, BitOr, Shl, Shr};
-fn add<A: Add<B, ()>, B>(lhs: A, rhs: B) {
+fn add<A: Add<B, Output=()>, B>(lhs: A, rhs: B) {
lhs + rhs;
drop(lhs); //~ ERROR use of moved value: `lhs`
drop(rhs); //~ ERROR use of moved value: `rhs`
}
-fn sub<A: Sub<B, ()>, B>(lhs: A, rhs: B) {
+fn sub<A: Sub<B, Output=()>, B>(lhs: A, rhs: B) {
lhs - rhs;
drop(lhs); //~ ERROR use of moved value: `lhs`
drop(rhs); //~ ERROR use of moved value: `rhs`
}
-fn mul<A: Mul<B, ()>, B>(lhs: A, rhs: B) {
+fn mul<A: Mul<B, Output=()>, B>(lhs: A, rhs: B) {
lhs * rhs;
drop(lhs); //~ ERROR use of moved value: `lhs`
drop(rhs); //~ ERROR use of moved value: `rhs`
}
-fn div<A: Div<B, ()>, B>(lhs: A, rhs: B) {
+fn div<A: Div<B, Output=()>, B>(lhs: A, rhs: B) {
lhs / rhs;
drop(lhs); //~ ERROR use of moved value: `lhs`
drop(rhs); //~ ERROR use of moved value: `rhs`
}
-fn rem<A: Rem<B, ()>, B>(lhs: A, rhs: B) {
+fn rem<A: Rem<B, Output=()>, B>(lhs: A, rhs: B) {
lhs % rhs;
drop(lhs); //~ ERROR use of moved value: `lhs`
drop(rhs); //~ ERROR use of moved value: `rhs`
}
-fn bitand<A: BitAnd<B, ()>, B>(lhs: A, rhs: B) {
+fn bitand<A: BitAnd<B, Output=()>, B>(lhs: A, rhs: B) {
lhs & rhs;
drop(lhs); //~ ERROR use of moved value: `lhs`
drop(rhs); //~ ERROR use of moved value: `rhs`
}
-fn bitor<A: BitOr<B, ()>, B>(lhs: A, rhs: B) {
+fn bitor<A: BitOr<B, Output=()>, B>(lhs: A, rhs: B) {
lhs | rhs;
drop(lhs); //~ ERROR use of moved value: `lhs`
drop(rhs); //~ ERROR use of moved value: `rhs`
}
-fn bitxor<A: BitXor<B, ()>, B>(lhs: A, rhs: B) {
+fn bitxor<A: BitXor<B, Output=()>, B>(lhs: A, rhs: B) {
lhs ^ rhs;
drop(lhs); //~ ERROR use of moved value: `lhs`
drop(rhs); //~ ERROR use of moved value: `rhs`
}
-fn shl<A: Shl<B, ()>, B>(lhs: A, rhs: B) {
+fn shl<A: Shl<B, Output=()>, B>(lhs: A, rhs: B) {
lhs << rhs;
drop(lhs); //~ ERROR use of moved value: `lhs`
drop(rhs); //~ ERROR use of moved value: `rhs`
}
-fn shr<A: Shr<B, ()>, B>(lhs: A, rhs: B) {
+fn shr<A: Shr<B, Output=()>, B>(lhs: A, rhs: B) {
lhs >> rhs;
drop(lhs); //~ ERROR use of moved value: `lhs`
drop(rhs); //~ ERROR use of moved value: `rhs`
// Test that move restrictions are enforced on overloaded binary operations
+#![feature(associated_types, default_type_params)]
+
use std::ops::Add;
-fn double_move<T: Add<T, ()>>(x: T) {
+fn double_move<T: Add<Output=()>>(x: T) {
x
+
x; //~ ERROR: use of moved value
}
-fn move_then_borrow<T: Add<T, ()> + Clone>(x: T) {
+fn move_then_borrow<T: Add<Output=()> + Clone>(x: T) {
x
+
x.clone(); //~ ERROR: use of moved value
}
-fn move_borrowed<T: Add<T, ()>>(x: T, mut y: T) {
+fn move_borrowed<T: Add<Output=()>>(x: T, mut y: T) {
let m = &x;
let n = &mut y;
y; //~ ERROR: cannot move out of `y` because it is borrowed
}
-fn illegal_dereference<T: Add<T, ()>>(mut x: T, y: T) {
+fn illegal_dereference<T: Add<Output=()>>(mut x: T, y: T) {
let m = &mut x;
let n = &y;
struct Foo;
-impl<'a, 'b> Add<&'b Foo, ()> for &'a mut Foo {
+impl<'a, 'b> Add<&'b Foo> for &'a mut Foo {
+ type Output = ();
+
fn add(self, _: &Foo) {}
}
-impl<'a, 'b> Add<&'b mut Foo, ()> for &'a Foo {
+impl<'a, 'b> Add<&'b mut Foo> for &'a Foo {
+ type Output = ();
+
fn add(self, _: &mut Foo) {}
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+#![feature(associated_types)]
+
use std::ops::Add;
#[derive(Clone)]
struct foo(Box<uint>);
-impl Add<foo, foo> for foo {
+impl Add for foo {
+ type Output = foo;
+
fn add(self, f: foo) -> foo {
let foo(box i) = self;
let foo(box j) = f;
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+#![feature(associated_types, default_type_params)]
+
use std::ops::Add;
#[derive(Copy)]
y: int,
}
-impl Add<int, int> for Point {
+impl Add<int> for Point {
+ type Output = int;
+
fn add(self, z: int) -> int {
self.x + self.y + z
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-
trait vec_monad<A> {
fn bind<B>(&self, f: |A| -> Vec<B> );
}
// (In this case the mul method should take &f64 and not f64)
// See: #11450
+#![feature(associated_types, default_type_params)]
+
use std::ops::Mul;
struct Vec1 {
}
// Expecting value in input signature
-impl Mul<f64, Vec1> for Vec1 {
+impl Mul<f64> for Vec1 {
+ type Output = Vec1;
+
fn mul(self, s: &f64) -> Vec1 {
//~^ ERROR: method `mul` has an incompatible type for trait: expected f64, found &-ptr
Vec1 {
}
// Wrong type parameter ordering
-impl Mul<Vec2, f64> for Vec2 {
+impl Mul<Vec2> for Vec2 {
+ type Output = f64;
+
fn mul(self, s: f64) -> Vec2 {
//~^ ERROR: method `mul` has an incompatible type for trait: expected struct Vec2, found f64
Vec2 {
}
// Unexpected return type
-impl Mul<f64, i32> for Vec3 {
+impl Mul<f64> for Vec3 {
+ type Output = i32;
+
fn mul(self, s: f64) -> f64 {
//~^ ERROR: method `mul` has an incompatible type for trait: expected i32, found f64
s
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use std::ops::Add;
+#![feature(associated_types)]
+
use std::num::Zero;
+use std::ops::Add;
#[derive(Zero)]
struct Vector2<T>(T, T);
-impl<T: Add<T, T>> Add<Vector2<T>, Vector2<T>> for Vector2<T> {
+impl<T: Add<Output=T>> Add for Vector2<T> {
+ type Output = Vector2<T>;
+
fn add(self, other: Vector2<T>) -> Vector2<T> {
match (self, other) {
(Vector2(x0, y0), Vector2(x1, y1)) => {
x: T, y: T, z: T,
}
-impl<T: Add<T, T>> Add<Vector3<T>, Vector3<T>> for Vector3<T> {
+impl<T: Add<Output=T>> Add for Vector3<T> {
+ type Output = Vector3<T>;
+
fn add(self, other: Vector3<T>) -> Vector3<T> {
Vector3 {
x: self.x + other.x,
z: Vector2<T>,
}
-impl<T: Add<T, T>> Add<Matrix3x2<T>, Matrix3x2<T>> for Matrix3x2<T> {
+impl<T: Add<Output=T>> Add for Matrix3x2<T> {
+ type Output = Matrix3x2<T>;
+
fn add(self, other: Matrix3x2<T>) -> Matrix3x2<T> {
Matrix3x2 {
x: self.x + other.x,
// If `Mul` used an associated type for its output, this test would
// work more smoothly.
-#![feature(old_orphan_check)]
+#![feature(associated_types, default_type_params, old_orphan_check)]
use std::ops::Mul;
trait RhsOfVec2Mul<Result> { fn mul_vec2_by(&self, lhs: &Vec2) -> Result; }
// Vec2's implementation of Mul "from the other side" using the above trait
-impl<Res, Rhs: RhsOfVec2Mul<Res>> Mul<Rhs,Res> for Vec2 {
+impl<Res, Rhs: RhsOfVec2Mul<Res>> Mul<Rhs> for Vec2 {
+ type Output = Res;
+
fn mul(self, rhs: Rhs) -> Res { rhs.mul_vec2_by(&self) }
}
fn X(&self) -> S;
}
-trait Movable<S: Add<S, S>>: Positioned<S> {
+trait Movable<S: Add<Output=S>>: Positioned<S> {
fn translate(&mut self, dx: S) {
let x = self.X() + dx;
self.SetX(x);
use std::ops::Add;
-fn foo<T: Add<T, T> + Clone>([x, y, z]: [T; 3]) -> (T, T, T) {
+fn foo<T: Add<Output=T> + Clone>([x, y, z]: [T; 3]) -> (T, T, T) {
(x.clone(), x.clone() + y.clone(), x + y + z)
}
fn bar(a: &'static str, b: &'static str) -> [&'static str; 4] {
// Test that we can overload the `+` operator for points so that two
// points can be added, and a point can be added to an integer.
+#![feature(associated_types, default_type_params)]
+
use std::ops;
#[derive(Show,PartialEq,Eq)]
y: int
}
-impl ops::Add<Point,Point> for Point {
+impl ops::Add for Point {
+ type Output = Point;
+
fn add(self, other: Point) -> Point {
Point {x: self.x + other.x, y: self.y + other.y}
}
}
-impl ops::Add<int,Point> for Point {
+impl ops::Add<int> for Point {
+ type Output = Point;
+
fn add(self, other: int) -> Point {
Point {x: self.x + other,
y: self.y + other}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+#![feature(associated_types)]
use std::cmp;
use std::ops;
y: int
}
-impl ops::Add<Point,Point> for Point {
+impl ops::Add for Point {
+ type Output = Point;
+
fn add(self, other: Point) -> Point {
Point {x: self.x + other.x, y: self.y + other.y}
}
}
-impl ops::Sub<Point,Point> for Point {
+impl ops::Sub for Point {
+ type Output = Point;
+
fn sub(self, other: Point) -> Point {
Point {x: self.x - other.x, y: self.y - other.y}
}
// Tests that nested vtables work with overloaded calls.
-#![feature(unboxed_closures)]
+#![feature(default_type_params, unboxed_closures)]
use std::ops::Fn;
use std::ops::Add;
struct G<A>;
-impl<'a, A: Add<int, int>> Fn<(A,), int> for G<A> {
+impl<'a, A: Add<int, Output=int>> Fn<(A,), int> for G<A> {
extern "rust-call" fn call(&self, (arg,): (A,)) -> int {
arg.add(1)
}
// except according to those terms.
-#![feature(simd)]
+#![feature(associated_types, simd)]
use std::ops;
impl Copy for f32x4 {}
-fn add<T: ops::Add<T, T>>(lhs: T, rhs: T) -> T {
+fn add<T: ops::Add<Output=T>>(lhs: T, rhs: T) -> T {
lhs + rhs
}
-impl ops::Add<f32x4, f32x4> for f32x4 {
+impl ops::Add for f32x4 {
+ type Output = f32x4;
+
fn add(self, rhs: f32x4) -> f32x4 {
self + rhs
}
fn X(&self) -> S;
}
-trait Movable<S: Add<S, S>>: Positioned<S> {
+trait Movable<S: Add<Output=S>>: Positioned<S> {
fn translate(&mut self, dx: S) {
let x = self.X() + dx;
self.SetX(x);
}
}
-impl<S: Clone + Add<S, S>> Movable<S> for Point<S> {}
+impl<S: Clone + Add<Output=S>> Movable<S> for Point<S> {}
pub fn main() {
let mut p = Point{ x: 1i, y: 2i};
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+#![feature(associated_types)]
+
use std::cmp::PartialEq;
use std::ops::{Add, Sub, Mul};
-trait MyNum : Add<Self,Self> + Sub<Self,Self> + Mul<Self,Self> + PartialEq + Clone { }
+trait MyNum : Add<Output=Self> + Sub<Output=Self> + Mul<Output=Self> + PartialEq + Clone { }
#[derive(Clone, Show)]
struct MyInt { val: int }
-impl Add<MyInt, MyInt> for MyInt {
+impl Add for MyInt {
+ type Output = MyInt;
+
fn add(self, other: MyInt) -> MyInt { mi(self.val + other.val) }
}
-impl Sub<MyInt, MyInt> for MyInt {
+impl Sub for MyInt {
+ type Output = MyInt;
+
fn sub(self, other: MyInt) -> MyInt { mi(self.val - other.val) }
}
-impl Mul<MyInt, MyInt> for MyInt {
+impl Mul for MyInt {
+ type Output = MyInt;
+
fn mul(self, other: MyInt) -> MyInt { mi(self.val * other.val) }
}