From dbd138302d13c94bd737ea70b83fe5ba610f2d4d Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Wed, 31 Dec 2014 15:45:13 -0500 Subject: [PATCH] use assoc types in binop traits --- src/libcollections/btree/set.rs | 16 +- src/libcollections/enum_set.rs | 16 +- src/libcollections/lib.rs | 1 + src/libcollections/string.rs | 4 +- src/libcollections/vec.rs | 4 +- src/libcore/iter.rs | 2 +- src/libcore/num/mod.rs | 46 ++--- src/libcore/ops.rs | 164 +++++++++++++----- src/libcoretest/num/mod.rs | 6 +- src/librustc/lib.rs | 1 + src/librustc/middle/ty.rs | 12 +- src/librustdoc/lib.rs | 1 + src/librustdoc/stability_summary.rs | 4 +- src/libstd/bitflags.rs | 16 +- src/libstd/collections/hash/set.rs | 16 +- src/libstd/lib.rs | 1 + src/libstd/num/mod.rs | 6 +- src/libstd/time/duration.rs | 16 +- src/libsyntax/codemap.rs | 16 +- src/libsyntax/ext/tt/transcribe.rs | 4 +- src/libsyntax/lib.rs | 1 + src/libtime/lib.rs | 10 +- .../trait_inheritance_overloading_xc.rs | 16 +- .../auxiliary/unboxed-closures-cross-crate.rs | 2 +- src/test/compile-fail/binop-consume-args.rs | 22 +-- src/test/compile-fail/binop-move-semantics.rs | 18 +- .../borrowck-loan-in-overloaded-op.rs | 5 +- .../borrowck-loan-rcvr-overloaded-op.rs | 6 +- src/test/compile-fail/issue-2149.rs | 1 + src/test/compile-fail/issue-3702-2.rs | 2 + src/test/compile-fail/issue-7575.rs | 2 + .../wrong-mul-method-signature.rs | 14 +- src/test/run-pass/deriving-zero.rs | 13 +- src/test/run-pass/issue-3743.rs | 6 +- src/test/run-pass/issue-3979-generics.rs | 2 +- src/test/run-pass/issue-7784.rs | 2 +- src/test/run-pass/operator-multidispatch.rs | 10 +- src/test/run-pass/operator-overloading.rs | 9 +- .../overloaded-calls-param-vtables.rs | 4 +- src/test/run-pass/simd-generics.rs | 8 +- .../run-pass/supertrait-default-generics.rs | 4 +- .../run-pass/trait-inheritance-overloading.rs | 16 +- 42 files changed, 372 insertions(+), 153 deletions(-) diff --git a/src/libcollections/btree/set.rs b/src/libcollections/btree/set.rs index 2935692ed1580..b8159c969a951 100644 --- a/src/libcollections/btree/set.rs +++ b/src/libcollections/btree/set.rs @@ -449,7 +449,9 @@ impl Default for BTreeSet { } #[unstable = "matches collection reform specification, waiting for dust to settle"] -impl<'a, 'b, T: Ord + Clone> Sub<&'b BTreeSet, BTreeSet> for &'a BTreeSet { +impl<'a, 'b, T: Ord + Clone> Sub<&'b BTreeSet> for &'a BTreeSet { + type Output = BTreeSet; + /// Returns the difference of `self` and `rhs` as a new `BTreeSet`. /// /// # Examples @@ -470,7 +472,9 @@ impl<'a, 'b, T: Ord + Clone> Sub<&'b BTreeSet, BTreeSet> for &'a BTreeSet< } #[unstable = "matches collection reform specification, waiting for dust to settle"] -impl<'a, 'b, T: Ord + Clone> BitXor<&'b BTreeSet, BTreeSet> for &'a BTreeSet { +impl<'a, 'b, T: Ord + Clone> BitXor<&'b BTreeSet> for &'a BTreeSet { + type Output = BTreeSet; + /// Returns the symmetric difference of `self` and `rhs` as a new `BTreeSet`. /// /// # Examples @@ -491,7 +495,9 @@ impl<'a, 'b, T: Ord + Clone> BitXor<&'b BTreeSet, BTreeSet> for &'a BTreeS } #[unstable = "matches collection reform specification, waiting for dust to settle"] -impl<'a, 'b, T: Ord + Clone> BitAnd<&'b BTreeSet, BTreeSet> for &'a BTreeSet { +impl<'a, 'b, T: Ord + Clone> BitAnd<&'b BTreeSet> for &'a BTreeSet { + type Output = BTreeSet; + /// Returns the intersection of `self` and `rhs` as a new `BTreeSet`. /// /// # Examples @@ -512,7 +518,9 @@ impl<'a, 'b, T: Ord + Clone> BitAnd<&'b BTreeSet, BTreeSet> for &'a BTreeS } #[unstable = "matches collection reform specification, waiting for dust to settle"] -impl<'a, 'b, T: Ord + Clone> BitOr<&'b BTreeSet, BTreeSet> for &'a BTreeSet { +impl<'a, 'b, T: Ord + Clone> BitOr<&'b BTreeSet> for &'a BTreeSet { + type Output = BTreeSet; + /// Returns the union of `self` and `rhs` as a new `BTreeSet`. /// /// # Examples diff --git a/src/libcollections/enum_set.rs b/src/libcollections/enum_set.rs index b484fc41ff6e5..f653f3264e393 100644 --- a/src/libcollections/enum_set.rs +++ b/src/libcollections/enum_set.rs @@ -183,25 +183,33 @@ impl EnumSet { } } -impl Sub, EnumSet> for EnumSet { +impl Sub for EnumSet { + type Output = EnumSet; + fn sub(self, e: EnumSet) -> EnumSet { EnumSet {bits: self.bits & !e.bits} } } -impl BitOr, EnumSet> for EnumSet { +impl BitOr for EnumSet { + type Output = EnumSet; + fn bitor(self, e: EnumSet) -> EnumSet { EnumSet {bits: self.bits | e.bits} } } -impl BitAnd, EnumSet> for EnumSet { +impl BitAnd for EnumSet { + type Output = EnumSet; + fn bitand(self, e: EnumSet) -> EnumSet { EnumSet {bits: self.bits & e.bits} } } -impl BitXor, EnumSet> for EnumSet { +impl BitXor for EnumSet { + type Output = EnumSet; + fn bitxor(self, e: EnumSet) -> EnumSet { EnumSet {bits: self.bits ^ e.bits} } diff --git a/src/libcollections/lib.rs b/src/libcollections/lib.rs index 688214140c1be..ed76917ca02c7 100644 --- a/src/libcollections/lib.rs +++ b/src/libcollections/lib.rs @@ -25,6 +25,7 @@ #![feature(macro_rules, default_type_params, phase, globs)] #![feature(unsafe_destructor, slicing_syntax)] #![feature(unboxed_closures)] +#![feature(associated_types)] #![no_std] #[phase(plugin, link)] extern crate core; diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index f703ff99660c6..d3fa900d80bf4 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -906,7 +906,9 @@ impl<'a, S: Str> Equiv 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 diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index a1952352badfa..3c42cf0290206 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -1449,7 +1449,9 @@ impl AsSlice for Vec { } } -impl<'a, T: Clone> Add<&'a [T], Vec> for Vec { +impl<'a, T: Clone> Add<&'a [T]> for Vec { + type Output = Vec; + #[inline] fn add(mut self, rhs: &[T]) -> Vec { self.push_all(rhs); diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index b0fd52896fe57..1a7ebd9b4fd4f 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -2354,7 +2354,7 @@ pub fn count(start: A, step: A) -> Counter { } #[unstable = "trait is unstable"] -impl + Clone> Iterator for Counter { +impl + Clone> Iterator for Counter { #[inline] fn next(&mut self) -> Option { let result = self.state.clone(); diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 0d2ce4f60718f..3ad07e68f44d9 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -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 + Rem>(x: T, y: T) -> (T, T) { +pub fn div_rem + Rem>(x: T, y: T) -> (T, T) { (x.clone() / y.clone(), x % y) } @@ -53,17 +53,17 @@ pub trait Int + NumCast + PartialOrd + Ord + PartialEq + Eq - + Add - + Sub - + Mul - + Div - + Rem + + Add + + Sub + + Mul + + Div + + Rem + Not - + BitAnd - + BitOr - + BitXor - + Shl - + Shr + + BitAnd + + BitOr + + BitXor + + Shl + + Shr { /// Returns the `0` value of this integer type. // FIXME (#5527): Should be an associated constant @@ -1246,11 +1246,11 @@ pub trait Float + PartialOrd + PartialEq + Neg - + Add - + Sub - + Mul - + Div - + Rem + + Add + + Sub + + Mul + + Div + + Rem { /// Returns the NaN value. fn nan() -> Self; @@ -1719,11 +1719,11 @@ macro_rules! trait_impl { #[allow(deprecated)] pub trait Num: PartialEq + Zero + One + Neg - + Add - + Sub - + Mul - + Div - + Rem {} + + Add + + Sub + + Mul + + Div + + Rem {} trait_impl! { Num for uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 } #[deprecated = "Generalised unsigned numbers are no longer supported"] @@ -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 { +pub trait Zero: Add { #[deprecated = "Use `Int::zero()` or `Float::zero()`."] fn zero() -> Self; #[deprecated = "Use `x == Int::zero()` or `x == Float::zero()`."] @@ -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 { +pub trait One: Mul { #[deprecated = "Use `Int::one()` or `Float::one()`."] fn one() -> Self; } diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index af07869e95feb..5b9183f0238fe 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -25,19 +25,25 @@ //! demonstrates adding and subtracting two `Point`s. //! //! ```rust +//! #![feature(associated_types)] +//! //! #[deriving(Show)] //! struct Point { //! x: int, //! y: int //! } //! -//! impl Add 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 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} //! } @@ -91,10 +97,13 @@ pub trait Drop { /// calling `add`, and therefore, `main` prints `Adding!`. /// /// ```rust +/// #![feature(associated_types)] /// #[deriving(Copy)] /// struct Foo; /// -/// impl Add for Foo { +/// impl Add for Foo { +/// type Output = Foo; +/// /// fn add(self, _rhs: Foo) -> Foo { /// println!("Adding!"); /// self @@ -106,14 +115,18 @@ pub trait Drop { /// } /// ``` #[lang="add"] -pub trait Add { +pub trait Add { + 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 } } @@ -130,10 +143,13 @@ add_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 } /// calling `sub`, and therefore, `main` prints `Subtracting!`. /// /// ```rust +/// #![feature(associated_types)] /// #[deriving(Copy)] /// struct Foo; /// -/// impl Sub for Foo { +/// impl Sub for Foo { +/// type Output = Foo; +/// /// fn sub(self, _rhs: Foo) -> Foo { /// println!("Subtracting!"); /// self @@ -145,14 +161,18 @@ add_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 } /// } /// ``` #[lang="sub"] -pub trait Sub { +pub trait Sub { + 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 } } @@ -169,10 +189,13 @@ sub_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 } /// calling `mul`, and therefore, `main` prints `Multiplying!`. /// /// ```rust +/// #![feature(associated_types)] /// #[deriving(Copy)] /// struct Foo; /// -/// impl Mul for Foo { +/// impl Mul for Foo { +/// type Output = Foo; +/// /// fn mul(self, _rhs: Foo) -> Foo { /// println!("Multiplying!"); /// self @@ -184,14 +207,18 @@ sub_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 } /// } /// ``` #[lang="mul"] -pub trait Mul { +pub trait Mul { + 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 } } @@ -208,10 +235,13 @@ mul_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 } /// calling `div`, and therefore, `main` prints `Dividing!`. /// /// ``` +/// #![feature(associated_types)] /// #[deriving(Copy)] /// struct Foo; /// -/// impl Div for Foo { +/// impl Div for Foo { +/// type Output = Foo; +/// /// fn div(self, _rhs: Foo) -> Foo { /// println!("Dividing!"); /// self @@ -223,14 +253,18 @@ mul_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 } /// } /// ``` #[lang="div"] -pub trait Div { +pub trait Div { + 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 } } @@ -247,10 +281,13 @@ div_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 } /// calling `rem`, and therefore, `main` prints `Remainder-ing!`. /// /// ``` +/// #![feature(associated_types)] /// #[deriving(Copy)] /// struct Foo; /// -/// impl Rem for Foo { +/// impl Rem for Foo { +/// type Output = Foo; +/// /// fn rem(self, _rhs: Foo) -> Foo { /// println!("Remainder-ing!"); /// self @@ -262,14 +299,18 @@ div_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 } /// } /// ``` #[lang="rem"] -pub trait Rem { +pub trait Rem { + 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 } } @@ -278,7 +319,9 @@ macro_rules! rem_impl { 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; } @@ -396,10 +439,13 @@ not_impl! { bool uint u8 u16 u32 u64 int i8 i16 i32 i64 } /// calling `bitand`, and therefore, `main` prints `Bitwise And-ing!`. /// /// ``` +/// #![feature(associated_types)] /// #[deriving(Copy)] /// struct Foo; /// -/// impl BitAnd for Foo { +/// impl BitAnd for Foo { +/// type Output = Foo; +/// /// fn bitand(self, _rhs: Foo) -> Foo { /// println!("Bitwise And-ing!"); /// self @@ -411,14 +457,18 @@ not_impl! { bool uint u8 u16 u32 u64 int i8 i16 i32 i64 } /// } /// ``` #[lang="bitand"] -pub trait BitAnd { +pub trait BitAnd { + 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 } } @@ -435,10 +485,13 @@ bitand_impl! { bool uint u8 u16 u32 u64 int i8 i16 i32 i64 } /// calling `bitor`, and therefore, `main` prints `Bitwise Or-ing!`. /// /// ``` +/// #![feature(associated_types)] /// #[deriving(Copy)] /// struct Foo; /// -/// impl BitOr for Foo { +/// impl BitOr for Foo { +/// type Output = Foo; +/// /// fn bitor(self, _rhs: Foo) -> Foo { /// println!("Bitwise Or-ing!"); /// self @@ -450,14 +503,18 @@ bitand_impl! { bool uint u8 u16 u32 u64 int i8 i16 i32 i64 } /// } /// ``` #[lang="bitor"] -pub trait BitOr { +pub trait BitOr { + 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 } } @@ -474,10 +531,13 @@ bitor_impl! { bool uint u8 u16 u32 u64 int i8 i16 i32 i64 } /// calling `bitxor`, and therefore, `main` prints `Bitwise Xor-ing!`. /// /// ``` +/// #![feature(associated_types)] /// #[deriving(Copy)] /// struct Foo; /// -/// impl BitXor for Foo { +/// impl BitXor for Foo { +/// type Output = Foo; +/// /// fn bitxor(self, _rhs: Foo) -> Foo { /// println!("Bitwise Xor-ing!"); /// self @@ -489,14 +549,18 @@ bitor_impl! { bool uint u8 u16 u32 u64 int i8 i16 i32 i64 } /// } /// ``` #[lang="bitxor"] -pub trait BitXor { +pub trait BitXor { + 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 } } @@ -513,10 +577,13 @@ bitxor_impl! { bool uint u8 u16 u32 u64 int i8 i16 i32 i64 } /// calling `shl`, and therefore, `main` prints `Shifting left!`. /// /// ``` +/// #![feature(associated_types)] /// #[deriving(Copy)] /// struct Foo; /// -/// impl Shl for Foo { +/// impl Shl for Foo { +/// type Output = Foo; +/// /// fn shl(self, _rhs: Foo) -> Foo { /// println!("Shifting left!"); /// self @@ -528,14 +595,18 @@ bitxor_impl! { bool uint u8 u16 u32 u64 int i8 i16 i32 i64 } /// } /// ``` #[lang="shl"] -pub trait Shl { +pub trait Shl { + 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 for $t { + impl Shl for $t { + type Output = $t; + #[inline] fn shl(self, other: uint) -> $t { self << other @@ -554,10 +625,13 @@ shl_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 } /// calling `shr`, and therefore, `main` prints `Shifting right!`. /// /// ``` +/// #![feature(associated_types)] /// #[deriving(Copy)] /// struct Foo; /// -/// impl Shr for Foo { +/// impl Shr for Foo { +/// type Output = Foo; +/// /// fn shr(self, _rhs: Foo) -> Foo { /// println!("Shifting right!"); /// self @@ -569,14 +643,18 @@ shl_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 } /// } /// ``` #[lang="shr"] -pub trait Shr { +pub trait Shr { + 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 for $t { + impl Shr for $t { + type Output = $t; + #[inline] fn shr(self, other: uint) -> $t { self >> other } } diff --git a/src/libcoretest/num/mod.rs b/src/libcoretest/num/mod.rs index acc593d7be9c0..3d18be49c0ad9 100644 --- a/src/libcoretest/num/mod.rs +++ b/src/libcoretest/num/mod.rs @@ -30,9 +30,9 @@ mod uint; /// Helper function for testing numeric operations 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/librustc/lib.rs b/src/librustc/lib.rs index 4647c92e3d1e8..067915f53d380 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -26,6 +26,7 @@ #![feature(slicing_syntax, unsafe_destructor)] #![feature(rustc_diagnostic_macros)] #![feature(unboxed_closures)] +#![feature(associated_types)] extern crate arena; extern crate flate; diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 8e7470f5084b0..e1402c7e6f082 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -3208,19 +3208,25 @@ impl TypeContents { } } -impl ops::BitOr 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 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 for TypeContents { +impl ops::Sub for TypeContents { + type Output = TypeContents; + fn sub(self, other: TypeContents) -> TypeContents { TypeContents {bits: self.bits & !other.bits} } diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index ccdc816425503..f0714c994b09e 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -20,6 +20,7 @@ #![allow(unknown_features)] #![feature(globs, macro_rules, phase, slicing_syntax)] #![feature(unboxed_closures)] +#![feature(associated_types)] extern crate arena; extern crate getopts; diff --git a/src/librustdoc/stability_summary.rs b/src/librustdoc/stability_summary.rs index 2e3adf8e76787..b39596fa72f72 100644 --- a/src/librustdoc/stability_summary.rs +++ b/src/librustdoc/stability_summary.rs @@ -40,7 +40,9 @@ pub struct Counts { pub unmarked: uint, } -impl Add for Counts { +impl Add for Counts { + type Output = Counts; + fn add(self, other: Counts) -> Counts { Counts { deprecated: self.deprecated + other.deprecated, diff --git a/src/libstd/bitflags.rs b/src/libstd/bitflags.rs index aeb4df402a2cf..faea80fbdbdf5 100644 --- a/src/libstd/bitflags.rs +++ b/src/libstd/bitflags.rs @@ -209,7 +209,9 @@ macro_rules! bitflags { } } - impl BitOr<$BitFlags, $BitFlags> for $BitFlags { + impl 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 BitXor<$BitFlags, $BitFlags> for $BitFlags { + impl 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 BitAnd<$BitFlags, $BitFlags> for $BitFlags { + impl 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 Sub<$BitFlags, $BitFlags> for $BitFlags { + impl 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 93f6895f6885b..27a6d5915f5db 100644 --- a/src/libstd/collections/hash/set.rs +++ b/src/libstd/collections/hash/set.rs @@ -624,7 +624,9 @@ impl, S, H: Hasher + Default> Default for HashSet { #[unstable = "matches collection reform specification, waiting for dust to settle"] 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 @@ -652,7 +654,9 @@ BitOr<&'b HashSet, HashSet> for &'a HashSet { #[unstable = "matches collection reform specification, waiting for dust to settle"] 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 @@ -680,7 +684,9 @@ BitAnd<&'b HashSet, HashSet> for &'a HashSet { #[unstable = "matches collection reform specification, waiting for dust to settle"] 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 @@ -708,7 +714,9 @@ BitXor<&'b HashSet, HashSet> for &'a HashSet { #[unstable = "matches collection reform specification, waiting for dust to settle"] 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/lib.rs b/src/libstd/lib.rs index 74c387c5eeaf1..654096ce49d5e 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -107,6 +107,7 @@ #![feature(macro_rules, globs, linkage, thread_local, asm)] #![feature(default_type_params, phase, lang_items, unsafe_destructor)] #![feature(slicing_syntax, unboxed_closures)] +#![feature(associated_types)] // Don't link to std. We are std. #![no_std] diff --git a/src/libstd/num/mod.rs b/src/libstd/num/mod.rs index 48ff1a364e93c..e6a52c9f6d257 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 51564b539768d..1e148105cc627 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; diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index e61afb8b193af..443c4e18a574e 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -48,13 +48,17 @@ impl Pos for BytePos { fn to_uint(&self) -> uint { let BytePos(n) = *self; n as uint } } -impl Add 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 for BytePos { +impl Sub for BytePos { + type Output = BytePos; + fn sub(self, rhs: BytePos) -> BytePos { BytePos((self.to_uint() - rhs.to_uint()) as u32) } @@ -65,13 +69,17 @@ impl Pos for CharPos { fn to_uint(&self) -> uint { let CharPos(n) = *self; n } } -impl Add for CharPos { +impl Add for CharPos { + type Output = CharPos; + fn add(self, rhs: CharPos) -> CharPos { CharPos(self.to_uint() + rhs.to_uint()) } } -impl Sub for CharPos { +impl Sub for CharPos { + type Output = CharPos; + fn sub(self, rhs: CharPos) -> CharPos { CharPos(self.to_uint() - rhs.to_uint()) } diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index deed0b78e87e4..8af5e952e9a11 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -106,7 +106,9 @@ enum LockstepIterSize { LisContradiction(String), } -impl Add for LockstepIterSize { +impl Add for LockstepIterSize { + type Output = LockstepIterSize; + fn add(self, other: LockstepIterSize) -> LockstepIterSize { match self { LisUnconstrained => other, diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index d5093c5055c79..d86db4e177e9b 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -26,6 +26,7 @@ #![feature(macro_rules, globs, default_type_params, phase, slicing_syntax)] #![feature(quote, unsafe_destructor)] #![feature(unboxed_closures)] +#![feature(associated_types)] extern crate arena; extern crate fmt_macros; diff --git a/src/libtime/lib.rs b/src/libtime/lib.rs index 87a00334c478f..b6c875559d792 100644 --- a/src/libtime/lib.rs +++ b/src/libtime/lib.rs @@ -21,6 +21,8 @@ html_root_url = "http://doc.rust-lang.org/nightly/", html_playground_url = "http://play.rust-lang.org/")] #![feature(phase, globs)] +#![feature(associated_types)] +#![feature(default_type_params)] #[cfg(test)] #[phase(plugin, link)] extern crate log; @@ -98,7 +100,9 @@ impl Timespec { } } -impl Add for Timespec { +impl Add 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 @@ -118,7 +122,9 @@ impl Add for Timespec { } } -impl Sub 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; diff --git a/src/test/auxiliary/trait_inheritance_overloading_xc.rs b/src/test/auxiliary/trait_inheritance_overloading_xc.rs index 61854aba2790d..d24c93b59f5fe 100644 --- a/src/test/auxiliary/trait_inheritance_overloading_xc.rs +++ b/src/test/auxiliary/trait_inheritance_overloading_xc.rs @@ -8,9 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(associated_types)] + use std::cmp::PartialEq; -pub trait MyNum : Add + Sub + Mul + PartialEq + Clone { +pub trait MyNum : Add + Sub + Mul + PartialEq + Clone { } #[deriving(Clone, Show)] @@ -18,15 +20,21 @@ pub struct MyInt { pub val: int } -impl Add for MyInt { +impl Add for MyInt { + type Output = MyInt; + fn add(self, other: MyInt) -> MyInt { mi(self.val + other.val) } } -impl Sub for MyInt { +impl Sub for MyInt { + type Output = MyInt; + fn sub(self, other: MyInt) -> MyInt { mi(self.val - other.val) } } -impl Mul for MyInt { +impl Mul for MyInt { + type Output = MyInt; + fn mul(self, other: MyInt) -> MyInt { mi(self.val * other.val) } } diff --git a/src/test/auxiliary/unboxed-closures-cross-crate.rs b/src/test/auxiliary/unboxed-closures-cross-crate.rs index 9a6a2c7495b79..6f05865919119 100644 --- a/src/test/auxiliary/unboxed-closures-cross-crate.rs +++ b/src/test/auxiliary/unboxed-closures-cross-crate.rs @@ -19,7 +19,7 @@ pub fn has_closures() -> uint { f() + g() } -pub fn has_generic_closures + Copy>(x: T, y: T) -> T { +pub fn has_generic_closures + Copy>(x: T, y: T) -> T { let mut f = move |&mut:| x; let g = |:| y; f() + g() diff --git a/src/test/compile-fail/binop-consume-args.rs b/src/test/compile-fail/binop-consume-args.rs index 2bdd148b99bd0..47aa842beb000 100644 --- a/src/test/compile-fail/binop-consume-args.rs +++ b/src/test/compile-fail/binop-consume-args.rs @@ -10,61 +10,63 @@ // Test that binary operators consume their arguments -fn add, B>(lhs: A, rhs: B) { +#![feature(associated_types, default_type_params)] + +fn add, 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, B>(lhs: A, rhs: B) { +fn sub, 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, B>(lhs: A, rhs: B) { +fn mul, 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, B>(lhs: A, rhs: B) { +fn div, 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, B>(lhs: A, rhs: B) { +fn rem, 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, B>(lhs: A, rhs: B) { +fn bitand, 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, B>(lhs: A, rhs: B) { +fn bitor, 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, B>(lhs: A, rhs: B) { +fn bitxor, 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, B>(lhs: A, rhs: B) { +fn shl, 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, B>(lhs: A, rhs: B) { +fn shr, B>(lhs: A, rhs: B) { lhs >> rhs; drop(lhs); //~ ERROR use of moved value: `lhs` drop(rhs); //~ ERROR use of moved value: `rhs` diff --git a/src/test/compile-fail/binop-move-semantics.rs b/src/test/compile-fail/binop-move-semantics.rs index d9440e1837572..d0c2cfb51267f 100644 --- a/src/test/compile-fail/binop-move-semantics.rs +++ b/src/test/compile-fail/binop-move-semantics.rs @@ -10,19 +10,21 @@ // Test that move restrictions are enforced on overloaded binary operations -fn double_move>(x: T) { +#![feature(associated_types, default_type_params)] + +fn double_move>(x: T) { x + x; //~ ERROR: use of moved value } -fn move_then_borrow + Clone>(x: T) { +fn move_then_borrow + Clone>(x: T) { x + x.clone(); //~ ERROR: use of moved value } -fn move_borrowed>(x: T, mut y: T) { +fn move_borrowed>(x: T, mut y: T) { let m = &x; let n = &mut y; @@ -31,7 +33,7 @@ fn move_borrowed>(x: T, mut y: T) { y; //~ ERROR: cannot move out of `y` because it is borrowed } -fn illegal_dereference>(mut x: T, y: T) { +fn illegal_dereference>(mut x: T, y: T) { let m = &mut x; let n = &y; @@ -42,11 +44,15 @@ fn illegal_dereference>(mut x: T, y: T) { 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) {} } diff --git a/src/test/compile-fail/borrowck-loan-in-overloaded-op.rs b/src/test/compile-fail/borrowck-loan-in-overloaded-op.rs index 692303fc1e481..54eb8a3e6b51a 100644 --- a/src/test/compile-fail/borrowck-loan-in-overloaded-op.rs +++ b/src/test/compile-fail/borrowck-loan-in-overloaded-op.rs @@ -8,11 +8,14 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(associated_types)] #[deriving(Clone)] struct foo(Box); -impl Add 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; diff --git a/src/test/compile-fail/borrowck-loan-rcvr-overloaded-op.rs b/src/test/compile-fail/borrowck-loan-rcvr-overloaded-op.rs index b83e1544c96d3..8eccb93ea7725 100644 --- a/src/test/compile-fail/borrowck-loan-rcvr-overloaded-op.rs +++ b/src/test/compile-fail/borrowck-loan-rcvr-overloaded-op.rs @@ -8,13 +8,17 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(associated_types, default_type_params)] + #[deriving(Copy)] struct Point { x: int, y: int, } -impl Add for Point { +impl Add for Point { + type Output = int; + fn add(self, z: int) -> int { self.x + self.y + z } diff --git a/src/test/compile-fail/issue-2149.rs b/src/test/compile-fail/issue-2149.rs index 3343e92252f8e..3f1cacd78d872 100644 --- a/src/test/compile-fail/issue-2149.rs +++ b/src/test/compile-fail/issue-2149.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// ignore-test FIXME(japaric) This ICEs trait vec_monad { fn bind(&self, f: |A| -> Vec ); diff --git a/src/test/compile-fail/issue-3702-2.rs b/src/test/compile-fail/issue-3702-2.rs index 54100d543dda0..2bc23ceb83685 100644 --- a/src/test/compile-fail/issue-3702-2.rs +++ b/src/test/compile-fail/issue-3702-2.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// ignore-test FIXME(japaric) this ICEs + trait Add { fn to_int(&self) -> int; fn add_dynamic(&self, other: &Add) -> int; diff --git a/src/test/compile-fail/issue-7575.rs b/src/test/compile-fail/issue-7575.rs index d5a1040d4b4d9..9185592d9e1ce 100644 --- a/src/test/compile-fail/issue-7575.rs +++ b/src/test/compile-fail/issue-7575.rs @@ -10,6 +10,8 @@ // Test the mechanism for warning about possible missing `self` declarations. +// ignore-test FIXME(japaric) this ICEs + trait CtxtFn { fn f8(self, uint) -> uint; fn f9(uint) -> uint; //~ NOTE candidate diff --git a/src/test/compile-fail/wrong-mul-method-signature.rs b/src/test/compile-fail/wrong-mul-method-signature.rs index b5e4cac75550f..9c5b1a0a52d62 100644 --- a/src/test/compile-fail/wrong-mul-method-signature.rs +++ b/src/test/compile-fail/wrong-mul-method-signature.rs @@ -13,12 +13,16 @@ // (In this case the mul method should take &f64 and not f64) // See: #11450 +#![feature(associated_types, default_type_params)] + struct Vec1 { x: f64 } // Expecting value in input signature -impl Mul for Vec1 { +impl Mul 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 { @@ -33,7 +37,9 @@ struct Vec2 { } // Wrong type parameter ordering -impl Mul for Vec2 { +impl Mul 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 { @@ -50,7 +56,9 @@ struct Vec3 { } // Unexpected return type -impl Mul for Vec3 { +impl Mul 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 diff --git a/src/test/run-pass/deriving-zero.rs b/src/test/run-pass/deriving-zero.rs index 88f3e5775b78b..d0a8589685777 100644 --- a/src/test/run-pass/deriving-zero.rs +++ b/src/test/run-pass/deriving-zero.rs @@ -8,13 +8,16 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(associated_types)] use std::num::Zero; #[deriving(Zero)] struct Vector2(T, T); -impl> Add, Vector2> for Vector2 { +impl> Add for Vector2 { + type Output = Vector2; + fn add(self, other: Vector2) -> Vector2 { match (self, other) { (Vector2(x0, y0), Vector2(x1, y1)) => { @@ -29,7 +32,9 @@ struct Vector3 { x: T, y: T, z: T, } -impl> Add, Vector3> for Vector3 { +impl> Add for Vector3 { + type Output = Vector3; + fn add(self, other: Vector3) -> Vector3 { Vector3 { x: self.x + other.x, @@ -46,7 +51,9 @@ struct Matrix3x2 { z: Vector2, } -impl> Add, Matrix3x2> for Matrix3x2 { +impl> Add for Matrix3x2 { + type Output = Matrix3x2; + fn add(self, other: Matrix3x2) -> Matrix3x2 { Matrix3x2 { x: self.x + other.x, diff --git a/src/test/run-pass/issue-3743.rs b/src/test/run-pass/issue-3743.rs index 80d3d29bc004d..dff5753ba3496 100644 --- a/src/test/run-pass/issue-3743.rs +++ b/src/test/run-pass/issue-3743.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(associated_types, default_type_params)] + struct Vec2 { x: f64, y: f64 @@ -27,7 +29,9 @@ impl Vec2 { trait RhsOfVec2Mul { fn mul_vec2_by(&self, lhs: &Vec2) -> Result; } // Vec2's implementation of Mul "from the other side" using the above trait -impl> Mul for Vec2 { +impl> Mul for Vec2 { + type Output = Res; + fn mul(self, rhs: Rhs) -> Res { rhs.mul_vec2_by(&self) } } diff --git a/src/test/run-pass/issue-3979-generics.rs b/src/test/run-pass/issue-3979-generics.rs index 86cdd6135ecf2..b267d835a10fc 100644 --- a/src/test/run-pass/issue-3979-generics.rs +++ b/src/test/run-pass/issue-3979-generics.rs @@ -13,7 +13,7 @@ trait Positioned { fn X(&self) -> S; } -trait Movable>: Positioned { +trait Movable>: Positioned { fn translate(&mut self, dx: S) { let x = self.X() + dx; self.SetX(x); diff --git a/src/test/run-pass/issue-7784.rs b/src/test/run-pass/issue-7784.rs index b936eb322fc5f..57922195b7e54 100644 --- a/src/test/run-pass/issue-7784.rs +++ b/src/test/run-pass/issue-7784.rs @@ -10,7 +10,7 @@ #![feature(advanced_slice_patterns)] -fn foo + Clone>([x, y, z]: [T; 3]) -> (T, T, T) { +fn foo + 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] { diff --git a/src/test/run-pass/operator-multidispatch.rs b/src/test/run-pass/operator-multidispatch.rs index cb3397c00bc57..6890836427cc6 100644 --- a/src/test/run-pass/operator-multidispatch.rs +++ b/src/test/run-pass/operator-multidispatch.rs @@ -11,6 +11,8 @@ // 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; #[deriving(Show,PartialEq,Eq)] @@ -19,13 +21,17 @@ struct Point { y: int } -impl ops::Add 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 for Point { +impl ops::Add for Point { + type Output = Point; + fn add(self, other: int) -> Point { Point {x: self.x + other, y: self.y + other} diff --git a/src/test/run-pass/operator-overloading.rs b/src/test/run-pass/operator-overloading.rs index 1e646e9399c56..146f2acda1e11 100644 --- a/src/test/run-pass/operator-overloading.rs +++ b/src/test/run-pass/operator-overloading.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(associated_types)] use std::cmp; use std::ops; @@ -18,13 +19,17 @@ struct Point { y: int } -impl ops::Add 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 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} } diff --git a/src/test/run-pass/overloaded-calls-param-vtables.rs b/src/test/run-pass/overloaded-calls-param-vtables.rs index 2e8ec3916bd89..c7a53e1306a28 100644 --- a/src/test/run-pass/overloaded-calls-param-vtables.rs +++ b/src/test/run-pass/overloaded-calls-param-vtables.rs @@ -10,13 +10,13 @@ // Tests that nested vtables work with overloaded calls. -#![feature(unboxed_closures)] +#![feature(default_type_params, unboxed_closures)] use std::ops::Fn; struct G; -impl<'a, A: Add> Fn<(A,), int> for G { +impl<'a, A: Add> Fn<(A,), int> for G { extern "rust-call" fn call(&self, (arg,): (A,)) -> int { arg.add(1) } diff --git a/src/test/run-pass/simd-generics.rs b/src/test/run-pass/simd-generics.rs index 42f93a97142d2..ceb6b79042681 100644 --- a/src/test/run-pass/simd-generics.rs +++ b/src/test/run-pass/simd-generics.rs @@ -9,7 +9,7 @@ // except according to those terms. -#![feature(simd)] +#![feature(associated_types, simd)] use std::ops; @@ -17,11 +17,13 @@ use std::ops; impl Copy for f32x4 {} -fn add>(lhs: T, rhs: T) -> T { +fn add>(lhs: T, rhs: T) -> T { lhs + rhs } -impl ops::Add for f32x4 { +impl ops::Add for f32x4 { + type Output = f32x4; + fn add(self, rhs: f32x4) -> f32x4 { self + rhs } diff --git a/src/test/run-pass/supertrait-default-generics.rs b/src/test/run-pass/supertrait-default-generics.rs index 873941395fead..c9c34d0acaead 100644 --- a/src/test/run-pass/supertrait-default-generics.rs +++ b/src/test/run-pass/supertrait-default-generics.rs @@ -15,7 +15,7 @@ trait Positioned { fn X(&self) -> S; } -trait Movable>: Positioned { +trait Movable>: Positioned { fn translate(&mut self, dx: S) { let x = self.X() + dx; self.SetX(x); @@ -33,7 +33,7 @@ impl Positioned for Point { } } -impl> Movable for Point {} +impl> Movable for Point {} pub fn main() { let mut p = Point{ x: 1i, y: 2i}; diff --git a/src/test/run-pass/trait-inheritance-overloading.rs b/src/test/run-pass/trait-inheritance-overloading.rs index 5f8e945cce860..5f07d9e8c49e3 100644 --- a/src/test/run-pass/trait-inheritance-overloading.rs +++ b/src/test/run-pass/trait-inheritance-overloading.rs @@ -8,22 +8,30 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(associated_types)] + use std::cmp::PartialEq; -trait MyNum : Add + Sub + Mul + PartialEq + Clone { } +trait MyNum : Add + Sub + Mul + PartialEq + Clone { } #[deriving(Clone, Show)] struct MyInt { val: int } -impl Add for MyInt { +impl Add for MyInt { + type Output = MyInt; + fn add(self, other: MyInt) -> MyInt { mi(self.val + other.val) } } -impl Sub for MyInt { +impl Sub for MyInt { + type Output = MyInt; + fn sub(self, other: MyInt) -> MyInt { mi(self.val - other.val) } } -impl Mul for MyInt { +impl Mul for MyInt { + type Output = MyInt; + fn mul(self, other: MyInt) -> MyInt { mi(self.val * other.val) } }