Fix run-pass tests

This commit is contained in:
Jorge Aparicio 2014-12-01 17:33:22 -05:00
parent 2b17083988
commit 971add88d8
11 changed files with 51 additions and 51 deletions

View File

@ -10,24 +10,24 @@
use std::cmp::PartialEq; use std::cmp::PartialEq;
pub trait MyNum : Add<Self,Self> + Sub<Self,Self> + Mul<Self,Self> + PartialEq { pub trait MyNum : Add<Self,Self> + Sub<Self,Self> + Mul<Self,Self> + PartialEq + Clone {
} }
#[deriving(Show)] #[deriving(Clone, Show)]
pub struct MyInt { pub struct MyInt {
pub val: int pub val: int
} }
impl Add<MyInt, MyInt> for MyInt { impl Add<MyInt, MyInt> for MyInt {
fn add(&self, other: &MyInt) -> MyInt { mi(self.val + other.val) } fn add(self, other: MyInt) -> MyInt { mi(self.val + other.val) }
} }
impl Sub<MyInt, MyInt> for MyInt { impl Sub<MyInt, MyInt> for MyInt {
fn sub(&self, other: &MyInt) -> MyInt { mi(self.val - other.val) } fn sub(self, other: MyInt) -> MyInt { mi(self.val - other.val) }
} }
impl Mul<MyInt, MyInt> for MyInt { impl Mul<MyInt, MyInt> for MyInt {
fn mul(&self, other: &MyInt) -> MyInt { mi(self.val * other.val) } fn mul(self, other: MyInt) -> MyInt { mi(self.val * other.val) }
} }
impl PartialEq for MyInt { impl PartialEq for MyInt {

View File

@ -16,30 +16,30 @@ fn main() {
assert_eq!(false != true, true); assert_eq!(false != true, true);
assert_eq!(false.ne(&false), false); assert_eq!(false.ne(&false), false);
assert_eq!(false.bitand(&false), false); assert_eq!(false.bitand(false), false);
assert_eq!(true.bitand(&false), false); assert_eq!(true.bitand(false), false);
assert_eq!(false.bitand(&true), false); assert_eq!(false.bitand(true), false);
assert_eq!(true.bitand(&true), true); assert_eq!(true.bitand(true), true);
assert_eq!(false & false, false); assert_eq!(false & false, false);
assert_eq!(true & false, false); assert_eq!(true & false, false);
assert_eq!(false & true, false); assert_eq!(false & true, false);
assert_eq!(true & true, true); assert_eq!(true & true, true);
assert_eq!(false.bitor(&false), false); assert_eq!(false.bitor(false), false);
assert_eq!(true.bitor(&false), true); assert_eq!(true.bitor(false), true);
assert_eq!(false.bitor(&true), true); assert_eq!(false.bitor(true), true);
assert_eq!(true.bitor(&true), true); assert_eq!(true.bitor(true), true);
assert_eq!(false | false, false); assert_eq!(false | false, false);
assert_eq!(true | false, true); assert_eq!(true | false, true);
assert_eq!(false | true, true); assert_eq!(false | true, true);
assert_eq!(true | true, true); assert_eq!(true | true, true);
assert_eq!(false.bitxor(&false), false); assert_eq!(false.bitxor(false), false);
assert_eq!(true.bitxor(&false), true); assert_eq!(true.bitxor(false), true);
assert_eq!(false.bitxor(&true), true); assert_eq!(false.bitxor(true), true);
assert_eq!(true.bitxor(&true), false); assert_eq!(true.bitxor(true), false);
assert_eq!(false ^ false, false); assert_eq!(false ^ false, false);
assert_eq!(true ^ false, true); assert_eq!(true ^ false, true);

View File

@ -15,10 +15,10 @@ use std::num::Zero;
struct Vector2<T>(T, T); struct Vector2<T>(T, T);
impl<T: Add<T, T>> Add<Vector2<T>, Vector2<T>> for Vector2<T> { impl<T: Add<T, T>> Add<Vector2<T>, Vector2<T>> for Vector2<T> {
fn add(&self, other: &Vector2<T>) -> Vector2<T> { fn add(self, other: Vector2<T>) -> Vector2<T> {
match (self, other) { match (self, other) {
(&Vector2(ref x0, ref y0), &Vector2(ref x1, ref y1)) => { (Vector2(x0, y0), Vector2(x1, y1)) => {
Vector2(*x0 + *x1, *y0 + *y1) Vector2(x0 + x1, y0 + y1)
} }
} }
} }
@ -30,7 +30,7 @@ struct Vector3<T> {
} }
impl<T: Add<T, T>> Add<Vector3<T>, Vector3<T>> for Vector3<T> { impl<T: Add<T, T>> Add<Vector3<T>, Vector3<T>> for Vector3<T> {
fn add(&self, other: &Vector3<T>) -> Vector3<T> { fn add(self, other: Vector3<T>) -> Vector3<T> {
Vector3 { Vector3 {
x: self.x + other.x, x: self.x + other.x,
y: self.y + other.y, y: self.y + other.y,
@ -47,7 +47,7 @@ struct Matrix3x2<T> {
} }
impl<T: Add<T, T>> Add<Matrix3x2<T>, Matrix3x2<T>> for Matrix3x2<T> { impl<T: Add<T, T>> Add<Matrix3x2<T>, Matrix3x2<T>> for Matrix3x2<T> {
fn add(&self, other: &Matrix3x2<T>) -> Matrix3x2<T> { fn add(self, other: Matrix3x2<T>) -> Matrix3x2<T> {
Matrix3x2 { Matrix3x2 {
x: self.x + other.x, x: self.x + other.x,
y: self.y + other.y, y: self.y + other.y,

View File

@ -28,7 +28,7 @@ trait RhsOfVec2Mul<Result> { fn mul_vec2_by(&self, lhs: &Vec2) -> Result; }
// Vec2's implementation of Mul "from the other side" using the above trait // 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,Res> for Vec2 {
fn mul(&self, rhs: &Rhs) -> Res { rhs.mul_vec2_by(self) } fn mul(self, rhs: Rhs) -> Res { rhs.mul_vec2_by(&self) }
} }
// Implementation of 'f64 as right-hand-side of Vec2::Mul' // Implementation of 'f64 as right-hand-side of Vec2::Mul'

View File

@ -18,19 +18,19 @@
pub fn main() { pub fn main() {
// ints // ints
// num // num
assert_eq!(15i.add(&6), 21); assert_eq!(15i.add(6), 21);
assert_eq!(15i8.add(&6i8), 21i8); assert_eq!(15i8.add(6i8), 21i8);
assert_eq!(15i16.add(&6i16), 21i16); assert_eq!(15i16.add(6i16), 21i16);
assert_eq!(15i32.add(&6i32), 21i32); assert_eq!(15i32.add(6i32), 21i32);
assert_eq!(15i64.add(&6i64), 21i64); assert_eq!(15i64.add(6i64), 21i64);
// uints // uints
// num // num
assert_eq!(15u.add(&6u), 21u); assert_eq!(15u.add(6u), 21u);
assert_eq!(15u8.add(&6u8), 21u8); assert_eq!(15u8.add(6u8), 21u8);
assert_eq!(15u16.add(&6u16), 21u16); assert_eq!(15u16.add(6u16), 21u16);
assert_eq!(15u32.add(&6u32), 21u32); assert_eq!(15u32.add(6u32), 21u32);
assert_eq!(15u64.add(&6u64), 21u64); assert_eq!(15u64.add(6u64), 21u64);
// floats // floats
// num // num

View File

@ -20,13 +20,13 @@ struct Point {
} }
impl ops::Add<Point,Point> for Point { impl ops::Add<Point,Point> for Point {
fn add(&self, other: &Point) -> Point { fn add(self, other: Point) -> Point {
Point {x: self.x + (*other).x, y: self.y + (*other).y} Point {x: self.x + other.x, y: self.y + other.y}
} }
} }
impl ops::Add<int,Point> for Point { impl ops::Add<int,Point> for Point {
fn add(&self, &other: &int) -> Point { fn add(self, other: int) -> Point {
Point {x: self.x + other, Point {x: self.x + other,
y: self.y + other} y: self.y + other}
} }

View File

@ -12,21 +12,21 @@
use std::cmp; use std::cmp;
use std::ops; use std::ops;
#[deriving(Show)] #[deriving(Copy, Show)]
struct Point { struct Point {
x: int, x: int,
y: int y: int
} }
impl ops::Add<Point,Point> for Point { impl ops::Add<Point,Point> for Point {
fn add(&self, other: &Point) -> Point { fn add(self, other: Point) -> Point {
Point {x: self.x + (*other).x, y: self.y + (*other).y} Point {x: self.x + other.x, y: self.y + other.y}
} }
} }
impl ops::Sub<Point,Point> for Point { impl ops::Sub<Point,Point> for Point {
fn sub(&self, other: &Point) -> Point { fn sub(self, other: Point) -> Point {
Point {x: self.x - (*other).x, y: self.y - (*other).y} Point {x: self.x - other.x, y: self.y - other.y}
} }
} }

View File

@ -18,7 +18,7 @@ struct G;
impl<'a, A: Add<int, int>> Fn<(A,), int> for G { impl<'a, A: Add<int, int>> Fn<(A,), int> for G {
extern "rust-call" fn call(&self, (arg,): (A,)) -> int { extern "rust-call" fn call(&self, (arg,): (A,)) -> int {
arg.add(&1) arg.add(1)
} }
} }

View File

@ -22,8 +22,8 @@ fn add<T: ops::Add<T, T>>(lhs: T, rhs: T) -> T {
} }
impl ops::Add<f32x4, f32x4> for f32x4 { impl ops::Add<f32x4, f32x4> for f32x4 {
fn add(&self, rhs: &f32x4) -> f32x4 { fn add(self, rhs: f32x4) -> f32x4 {
*self + *rhs self + rhs
} }
} }

View File

@ -14,7 +14,7 @@ extern crate trait_inheritance_overloading_xc;
use trait_inheritance_overloading_xc::{MyNum, MyInt}; use trait_inheritance_overloading_xc::{MyNum, MyInt};
fn f<T:MyNum>(x: T, y: T) -> (T, T, T) { fn f<T:MyNum>(x: T, y: T) -> (T, T, T) {
return (x + y, x - y, x * y); return (x.clone() + y.clone(), x.clone() - y.clone(), x * y);
} }
fn mi(v: int) -> MyInt { MyInt { val: v } } fn mi(v: int) -> MyInt { MyInt { val: v } }

View File

@ -10,21 +10,21 @@
use std::cmp::PartialEq; use std::cmp::PartialEq;
trait MyNum : Add<Self,Self> + Sub<Self,Self> + Mul<Self,Self> + PartialEq { } trait MyNum : Add<Self,Self> + Sub<Self,Self> + Mul<Self,Self> + PartialEq + Clone { }
#[deriving(Show)] #[deriving(Clone, Show)]
struct MyInt { val: int } struct MyInt { val: int }
impl Add<MyInt, MyInt> for MyInt { impl Add<MyInt, MyInt> for MyInt {
fn add(&self, other: &MyInt) -> MyInt { mi(self.val + other.val) } fn add(self, other: MyInt) -> MyInt { mi(self.val + other.val) }
} }
impl Sub<MyInt, MyInt> for MyInt { impl Sub<MyInt, MyInt> for MyInt {
fn sub(&self, other: &MyInt) -> MyInt { mi(self.val - other.val) } fn sub(self, other: MyInt) -> MyInt { mi(self.val - other.val) }
} }
impl Mul<MyInt, MyInt> for MyInt { impl Mul<MyInt, MyInt> for MyInt {
fn mul(&self, other: &MyInt) -> MyInt { mi(self.val * other.val) } fn mul(self, other: MyInt) -> MyInt { mi(self.val * other.val) }
} }
impl PartialEq for MyInt { impl PartialEq for MyInt {
@ -35,7 +35,7 @@ impl PartialEq for MyInt {
impl MyNum for MyInt {} impl MyNum for MyInt {}
fn f<T:MyNum>(x: T, y: T) -> (T, T, T) { fn f<T:MyNum>(x: T, y: T) -> (T, T, T) {
return (x + y, x - y, x * y); return (x.clone() + y.clone(), x.clone() - y.clone(), x * y);
} }
fn mi(v: int) -> MyInt { MyInt { val: v } } fn mi(v: int) -> MyInt { MyInt { val: v } }