Convert Num to explicit self
This commit is contained in:
parent
e23ea24aed
commit
4ab1c8805a
@ -163,14 +163,14 @@ impl f32 : cmp::Ord {
|
||||
}
|
||||
|
||||
impl f32: num::Num {
|
||||
pure fn add(other: &f32) -> f32 { return self + *other; }
|
||||
pure fn sub(other: &f32) -> f32 { return self - *other; }
|
||||
pure fn mul(other: &f32) -> f32 { return self * *other; }
|
||||
pure fn div(other: &f32) -> f32 { return self / *other; }
|
||||
pure fn modulo(other: &f32) -> f32 { return self % *other; }
|
||||
pure fn neg() -> f32 { return -self; }
|
||||
pure fn add(&self, other: &f32) -> f32 { return *self + *other; }
|
||||
pure fn sub(&self, other: &f32) -> f32 { return *self - *other; }
|
||||
pure fn mul(&self, other: &f32) -> f32 { return *self * *other; }
|
||||
pure fn div(&self, other: &f32) -> f32 { return *self / *other; }
|
||||
pure fn modulo(&self, other: &f32) -> f32 { return *self % *other; }
|
||||
pure fn neg(&self) -> f32 { return -*self; }
|
||||
|
||||
pure fn to_int() -> int { return self as int; }
|
||||
pure fn to_int(&self) -> int { return *self as int; }
|
||||
static pure fn from_int(n: int) -> f32 { return n as f32; }
|
||||
}
|
||||
|
||||
|
@ -182,14 +182,14 @@ impl f64 : cmp::Ord {
|
||||
}
|
||||
|
||||
impl f64: num::Num {
|
||||
pure fn add(other: &f64) -> f64 { return self + *other; }
|
||||
pure fn sub(other: &f64) -> f64 { return self - *other; }
|
||||
pure fn mul(other: &f64) -> f64 { return self * *other; }
|
||||
pure fn div(other: &f64) -> f64 { return self / *other; }
|
||||
pure fn modulo(other: &f64) -> f64 { return self % *other; }
|
||||
pure fn neg() -> f64 { return -self; }
|
||||
pure fn add(&self, other: &f64) -> f64 { return *self + *other; }
|
||||
pure fn sub(&self, other: &f64) -> f64 { return *self - *other; }
|
||||
pure fn mul(&self, other: &f64) -> f64 { return *self * *other; }
|
||||
pure fn div(&self, other: &f64) -> f64 { return *self / *other; }
|
||||
pure fn modulo(&self, other: &f64) -> f64 { return *self % *other; }
|
||||
pure fn neg(&self) -> f64 { return -*self; }
|
||||
|
||||
pure fn to_int() -> int { return self as int; }
|
||||
pure fn to_int(&self) -> int { return *self as int; }
|
||||
static pure fn from_int(n: int) -> f64 { return n as f64; }
|
||||
}
|
||||
|
||||
|
@ -425,22 +425,22 @@ impl float : Ord {
|
||||
|
||||
impl float: num::Num {
|
||||
#[inline(always)]
|
||||
pub pure fn add(other: &float) -> float { return self + *other; }
|
||||
pub pure fn add(&self, other: &float) -> float { return *self + *other; }
|
||||
#[inline(always)]
|
||||
pub pure fn sub(other: &float) -> float { return self - *other; }
|
||||
pub pure fn sub(&self, other: &float) -> float { return *self - *other; }
|
||||
#[inline(always)]
|
||||
pub pure fn mul(other: &float) -> float { return self * *other; }
|
||||
pub pure fn mul(&self, other: &float) -> float { return *self * *other; }
|
||||
#[inline(always)]
|
||||
pub pure fn div(other: &float) -> float { return self / *other; }
|
||||
pub pure fn div(&self, other: &float) -> float { return *self / *other; }
|
||||
#[inline(always)]
|
||||
pure fn modulo(other: &float) -> float { return self % *other; }
|
||||
pure fn modulo(&self, other: &float) -> float { return *self % *other; }
|
||||
#[inline(always)]
|
||||
pure fn neg() -> float { return -self; }
|
||||
pure fn neg(&self) -> float { return -*self; }
|
||||
|
||||
#[inline(always)]
|
||||
pure fn to_int() -> int { return self as int; }
|
||||
pure fn to_int(&self) -> int { return *self as int; }
|
||||
#[inline(always)]
|
||||
static pure fn from_int(n: int) -> float { return n as float; }
|
||||
static pure fn from_int(&self, n: int) -> float { return n as float; }
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -79,14 +79,14 @@ impl T : Eq {
|
||||
}
|
||||
|
||||
impl T: num::Num {
|
||||
pure fn add(other: &T) -> T { return self + *other; }
|
||||
pure fn sub(other: &T) -> T { return self - *other; }
|
||||
pure fn mul(other: &T) -> T { return self * *other; }
|
||||
pure fn div(other: &T) -> T { return self / *other; }
|
||||
pure fn modulo(other: &T) -> T { return self % *other; }
|
||||
pure fn neg() -> T { return -self; }
|
||||
pure fn add(&self, other: &T) -> T { return *self + *other; }
|
||||
pure fn sub(&self, other: &T) -> T { return *self - *other; }
|
||||
pure fn mul(&self, other: &T) -> T { return *self * *other; }
|
||||
pure fn div(&self, other: &T) -> T { return *self / *other; }
|
||||
pure fn modulo(&self, other: &T) -> T { return *self % *other; }
|
||||
pure fn neg(&self) -> T { return -*self; }
|
||||
|
||||
pure fn to_int() -> int { return self as int; }
|
||||
pure fn to_int(&self) -> int { return *self as int; }
|
||||
static pure fn from_int(n: int) -> T { return n as T; }
|
||||
}
|
||||
|
||||
|
@ -12,13 +12,13 @@
|
||||
|
||||
pub trait Num {
|
||||
// FIXME: Trait composition. (#2616)
|
||||
pure fn add(other: &self) -> self;
|
||||
pure fn sub(other: &self) -> self;
|
||||
pure fn mul(other: &self) -> self;
|
||||
pure fn div(other: &self) -> self;
|
||||
pure fn modulo(other: &self) -> self;
|
||||
pure fn neg() -> self;
|
||||
pure fn add(&self, other: &self) -> self;
|
||||
pure fn sub(&self, other: &self) -> self;
|
||||
pure fn mul(&self, other: &self) -> self;
|
||||
pure fn div(&self, other: &self) -> self;
|
||||
pure fn modulo(&self, other: &self) -> self;
|
||||
pure fn neg(&self) -> self;
|
||||
|
||||
pure fn to_int() -> int;
|
||||
pure fn to_int(&self) -> int;
|
||||
static pure fn from_int(n: int) -> self;
|
||||
}
|
||||
|
@ -73,14 +73,14 @@ impl T : Eq {
|
||||
}
|
||||
|
||||
impl T: num::Num {
|
||||
pure fn add(other: &T) -> T { return self + *other; }
|
||||
pure fn sub(other: &T) -> T { return self - *other; }
|
||||
pure fn mul(other: &T) -> T { return self * *other; }
|
||||
pure fn div(other: &T) -> T { return self / *other; }
|
||||
pure fn modulo(other: &T) -> T { return self % *other; }
|
||||
pure fn neg() -> T { return -self; }
|
||||
pure fn add(&self, other: &T) -> T { return *self + *other; }
|
||||
pure fn sub(&self, other: &T) -> T { return *self - *other; }
|
||||
pure fn mul(&self, other: &T) -> T { return *self * *other; }
|
||||
pure fn div(&self, other: &T) -> T { return *self / *other; }
|
||||
pure fn modulo(&self, other: &T) -> T { return *self % *other; }
|
||||
pure fn neg(&self) -> T { return -*self; }
|
||||
|
||||
pure fn to_int() -> int { return self as int; }
|
||||
pure fn to_int(&self) -> int { return *self as int; }
|
||||
static pure fn from_int(n: int) -> T { return n as T; }
|
||||
}
|
||||
|
||||
|
@ -59,27 +59,25 @@ impl BytePos: cmp::Ord {
|
||||
pure fn gt(&self, other: &BytePos) -> bool { **self > **other }
|
||||
}
|
||||
|
||||
impl BytePos: Num {
|
||||
pure fn add(other: &BytePos) -> BytePos {
|
||||
BytePos(*self + **other)
|
||||
#[cfg(stage0)]
|
||||
impl BytePos: Add<BytePos, BytePos> {
|
||||
pure fn add(rhs: &BytePos) -> BytePos {
|
||||
BytePos(*self + **rhs)
|
||||
}
|
||||
pure fn sub(other: &BytePos) -> BytePos {
|
||||
BytePos(*self - **other)
|
||||
}
|
||||
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
impl BytePos: Add<BytePos, BytePos> {
|
||||
pure fn add(&self, rhs: &BytePos) -> BytePos {
|
||||
BytePos(**self + **rhs)
|
||||
}
|
||||
pure fn mul(other: &BytePos) -> BytePos {
|
||||
BytePos(*self * (**other))
|
||||
}
|
||||
|
||||
impl BytePos: Sub<BytePos, BytePos> {
|
||||
pure fn sub(&self, rhs: &BytePos) -> BytePos {
|
||||
BytePos(**self - **rhs)
|
||||
}
|
||||
pure fn div(other: &BytePos) -> BytePos {
|
||||
BytePos(*self / **other)
|
||||
}
|
||||
pure fn modulo(other: &BytePos) -> BytePos {
|
||||
BytePos(*self % **other)
|
||||
}
|
||||
pure fn neg() -> BytePos {
|
||||
BytePos(-*self)
|
||||
}
|
||||
pure fn to_int() -> int { *self as int }
|
||||
static pure fn from_int(+n: int) -> BytePos { BytePos(n as uint) }
|
||||
}
|
||||
|
||||
impl BytePos: to_bytes::IterBytes {
|
||||
@ -105,35 +103,33 @@ impl CharPos: cmp::Ord {
|
||||
pure fn gt(&self, other: &CharPos) -> bool { **self > **other }
|
||||
}
|
||||
|
||||
impl CharPos: Num {
|
||||
pure fn add(other: &CharPos) -> CharPos {
|
||||
CharPos(*self + **other)
|
||||
}
|
||||
pure fn sub(other: &CharPos) -> CharPos {
|
||||
CharPos(*self - **other)
|
||||
}
|
||||
pure fn mul(other: &CharPos) -> CharPos {
|
||||
CharPos(*self * (**other))
|
||||
}
|
||||
pure fn div(other: &CharPos) -> CharPos {
|
||||
CharPos(*self / **other)
|
||||
}
|
||||
pure fn modulo(other: &CharPos) -> CharPos {
|
||||
CharPos(*self % **other)
|
||||
}
|
||||
pure fn neg() -> CharPos {
|
||||
CharPos(-*self)
|
||||
}
|
||||
pure fn to_int() -> int { *self as int }
|
||||
static pure fn from_int(+n: int) -> CharPos { CharPos(n as uint) }
|
||||
}
|
||||
|
||||
impl CharPos: to_bytes::IterBytes {
|
||||
pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) {
|
||||
(**self).iter_bytes(lsb0, f)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
impl CharPos: Add<CharPos, CharPos> {
|
||||
pure fn add(rhs: &CharPos) -> CharPos {
|
||||
CharPos(*self + **rhs)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
impl CharPos: Add<CharPos, CharPos> {
|
||||
pure fn add(&self, rhs: &CharPos) -> CharPos {
|
||||
CharPos(**self + **rhs)
|
||||
}
|
||||
}
|
||||
|
||||
impl CharPos: Sub<CharPos, CharPos> {
|
||||
pure fn sub(&self, rhs: &CharPos) -> CharPos {
|
||||
CharPos(**self - **rhs)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Spans represent a region of code, used for error reporting. Positions in spans
|
||||
are *absolute* positions from the beginning of the codemap, not positions
|
||||
|
Loading…
x
Reference in New Issue
Block a user