Skip to content

Commit f6c2ba0

Browse files
committed
---
yaml --- r: 159580 b: refs/heads/auto c: 2619671 h: refs/heads/master v: v3
1 parent 64ced21 commit f6c2ba0

File tree

14 files changed

+84
-69
lines changed

14 files changed

+84
-69
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1010
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1111
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1212
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
13-
refs/heads/auto: 46333d527b138e8e202380a5ce4409dfe1414148
13+
refs/heads/auto: 26196715e8e8fb3a578cc89a54c13773dc1a3772
1414
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1515
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1616
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/etc/vim/syntax/rust.vim

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ syn keyword rustTrait FromIterator IntoIterator Extend ExactSize
9797
syn keyword rustTrait Iterator DoubleEndedIterator
9898
syn keyword rustTrait RandomAccessIterator CloneableIterator
9999
syn keyword rustTrait OrdIterator MutableDoubleEndedIterator
100-
syn keyword rustTrait Num NumCast
101-
syn keyword rustTrait Signed Unsigned Primitive Int Float
100+
syn keyword rustTrait NumCast Signed Int UnsignedInt Float
102101
syn keyword rustTrait FloatMath ToPrimitive FromPrimitive
103102
syn keyword rustTrait Box
104103
syn keyword rustTrait GenericPath Path PosixPath WindowsPath

branches/auto/src/libcore/fmt/float.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use char;
1414
use fmt;
1515
use iter::{range, DoubleEndedIterator};
16-
use num::{Float, FPNaN, FPInfinite, ToPrimitive, Primitive};
16+
use num::{Float, FPNaN, FPInfinite, ToPrimitive};
1717
use num::cast;
1818
use result::Ok;
1919
use slice::{mod, SlicePrelude};
@@ -79,7 +79,7 @@ static DIGIT_E_RADIX: uint = ('e' as uint) - ('a' as uint) + 11u;
7979
* - Fails if `radix` > 25 and `exp_format` is `ExpBin` due to conflict
8080
* between digit and exponent sign `'p'`.
8181
*/
82-
pub fn float_to_str_bytes_common<T: Primitive + Float, U>(
82+
pub fn float_to_str_bytes_common<T: Float, U>(
8383
num: T,
8484
radix: uint,
8585
negative_zero: bool,

branches/auto/src/libcore/fmt/num.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@ trait GenericRadix {
3535
fn fmt_int<T: Int>(&self, mut x: T, f: &mut fmt::Formatter) -> fmt::Result {
3636
// The radix can be as low as 2, so we need a buffer of at least 64
3737
// characters for a base 2 number.
38+
let zero = Int::zero();
39+
let is_positive = x >= zero;
3840
let mut buf = [0u8, ..64];
39-
let base = cast(self.base()).unwrap();
4041
let mut curr = buf.len();
41-
let is_positive = x >= Int::zero();
42+
let base = cast(self.base()).unwrap();
4243
if is_positive {
4344
// Accumulate each digit of the number from the least significant
4445
// to the most significant figure.
@@ -47,16 +48,16 @@ trait GenericRadix {
4748
x = x / base; // Deaccumulate the number.
4849
*byte = self.digit(cast(n).unwrap()); // Store the digit in the buffer.
4950
curr -= 1;
50-
if x == Int::zero() { break; } // No more digits left to accumulate.
51+
if x == zero { break }; // No more digits left to accumulate.
5152
}
5253
} else {
5354
// Do the same as above, but accounting for two's complement.
5455
for byte in buf.iter_mut().rev() {
55-
let n = -(x % base); // Get the current place value.
56+
let n = zero - (x % base); // Get the current place value.
5657
x = x / base; // Deaccumulate the number.
5758
*byte = self.digit(cast(n).unwrap()); // Store the digit in the buffer.
5859
curr -= 1;
59-
if x == Int::zero() { break; } // No more digits left to accumulate.
60+
if x == zero { break }; // No more digits left to accumulate.
6061
}
6162
}
6263
f.pad_integral(is_positive, self.prefix(), buf[curr..])

branches/auto/src/libcore/num/mod.rs

Lines changed: 60 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -19,39 +19,22 @@ use {int, i8, i16, i32, i64};
1919
use {uint, u8, u16, u32, u64};
2020
use {f32, f64};
2121
use clone::Clone;
22-
use cmp::{Ord, PartialEq, PartialOrd};
22+
use cmp::{PartialEq, Eq};
23+
use cmp::{PartialOrd, Ord};
2324
use kinds::Copy;
2425
use mem::size_of;
2526
use ops::{Add, Sub, Mul, Div, Rem, Neg};
2627
use ops::{Not, BitAnd, BitOr, BitXor, Shl, Shr};
2728
use option::{Option, Some, None};
2829

29-
/// The base trait for numeric types
30-
#[allow(deprecated)]
31-
pub trait Num: PartialEq + Zero + One
32-
+ Neg<Self>
33-
+ Add<Self,Self>
34-
+ Sub<Self,Self>
35-
+ Mul<Self,Self>
36-
+ Div<Self,Self>
37-
+ Rem<Self,Self> {}
38-
39-
macro_rules! trait_impl(
40-
($name:ident for $($t:ty)*) => ($(
41-
impl $name for $t {}
42-
)*)
43-
)
44-
45-
trait_impl!(Num for uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64)
46-
4730
/// Simultaneous division and remainder
4831
#[inline]
4932
pub fn div_rem<T: Div<T, T> + Rem<T, T>>(x: T, y: T) -> (T, T) {
5033
(x / y, x % y)
5134
}
5235

5336
/// Useful functions for signed numbers (i.e. numbers that can be negative).
54-
pub trait Signed: Num + Neg<Self> {
37+
pub trait Signed: Neg<Self> {
5538
/// Computes the absolute value.
5639
///
5740
/// For `f32` and `f64`, `NaN` will be returned if the number is `NaN`.
@@ -161,11 +144,6 @@ signed_float_impl!(f64, f64::NAN, f64::INFINITY, f64::NEG_INFINITY,
161144
/// * `-1` if the number is negative
162145
#[inline(always)] pub fn signum<T: Signed>(value: T) -> T { value.signum() }
163146

164-
/// A trait for values which cannot be negative
165-
pub trait Unsigned: Num {}
166-
167-
trait_impl!(Unsigned for uint u8 u16 u32 u64)
168-
169147
/// Raises a value to the power of exp, using exponentiation by squaring.
170148
///
171149
/// # Example
@@ -191,27 +169,25 @@ pub fn pow<T: Int>(mut base: T, mut exp: uint) -> T {
191169
}
192170
}
193171

194-
/// Specifies the available operations common to all of Rust's core numeric primitives.
195-
/// These may not always make sense from a purely mathematical point of view, but
196-
/// may be useful for systems programming.
197-
pub trait Primitive: Copy
198-
+ Clone
199-
+ Num
200-
+ NumCast
201-
+ PartialOrd {}
202-
203-
trait_impl!(Primitive for uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64)
204-
205172
/// A primitive signed or unsigned integer equipped with various bitwise
206173
/// operators, bit counting methods, and endian conversion functions.
207-
pub trait Int: Primitive
208-
+ Ord
209-
+ Not<Self>
210-
+ BitAnd<Self,Self>
211-
+ BitOr<Self,Self>
212-
+ BitXor<Self,Self>
213-
+ Shl<uint,Self>
214-
+ Shr<uint,Self> {
174+
pub trait Int
175+
: Copy + Clone
176+
+ NumCast
177+
+ PartialOrd + Ord
178+
+ PartialEq + Eq
179+
+ Add<Self,Self>
180+
+ Sub<Self,Self>
181+
+ Mul<Self,Self>
182+
+ Div<Self,Self>
183+
+ Rem<Self,Self>
184+
+ Not<Self>
185+
+ BitAnd<Self,Self>
186+
+ BitOr<Self,Self>
187+
+ BitXor<Self,Self>
188+
+ Shl<uint,Self>
189+
+ Shr<uint,Self>
190+
{
215191
/// Returns the `0` value of this integer.
216192
// FIXME (#5527): Should be an associated constant
217193
fn zero() -> Self;
@@ -1253,13 +1229,24 @@ pub enum FPCategory {
12531229
FPNormal,
12541230
}
12551231

1256-
/// Operations on primitive floating point numbers.
1232+
/// Operations on the built-in floating point numbers.
12571233
// FIXME(#5527): In a future version of Rust, many of these functions will
12581234
// become constants.
12591235
//
12601236
// FIXME(#8888): Several of these functions have a parameter named
12611237
// `unused_self`. Removing it requires #8888 to be fixed.
1262-
pub trait Float: Signed + Primitive {
1238+
pub trait Float
1239+
: Copy + Clone
1240+
+ NumCast
1241+
+ PartialOrd
1242+
+ PartialEq
1243+
+ Signed
1244+
+ Add<Self,Self>
1245+
+ Sub<Self,Self>
1246+
+ Mul<Self,Self>
1247+
+ Div<Self,Self>
1248+
+ Rem<Self,Self>
1249+
{
12631250
/// Returns the NaN value.
12641251
fn nan() -> Self;
12651252
/// Returns the infinite value.
@@ -1404,6 +1391,33 @@ pub trait Float: Signed + Primitive {
14041391

14051392
// DEPRECATED
14061393

1394+
macro_rules! trait_impl {
1395+
($name:ident for $($t:ty)*) => {
1396+
$(#[allow(deprecated)] impl $name for $t {})*
1397+
};
1398+
}
1399+
1400+
#[deprecated = "Generalised numbers are no longer supported"]
1401+
#[allow(deprecated)]
1402+
pub trait Num: PartialEq + Zero + One
1403+
+ Neg<Self>
1404+
+ Add<Self,Self>
1405+
+ Sub<Self,Self>
1406+
+ Mul<Self,Self>
1407+
+ Div<Self,Self>
1408+
+ Rem<Self,Self> {}
1409+
trait_impl!(Num for uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64)
1410+
1411+
#[deprecated = "Generalised unsigned numbers are no longer supported"]
1412+
#[allow(deprecated)]
1413+
pub trait Unsigned: Num {}
1414+
trait_impl!(Unsigned for uint u8 u16 u32 u64)
1415+
1416+
#[deprecated = "Use `Float` or `Int`"]
1417+
#[allow(deprecated)]
1418+
pub trait Primitive: Copy + Clone + Num + NumCast + PartialOrd {}
1419+
trait_impl!(Primitive for uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64)
1420+
14071421
#[deprecated = "The generic `Zero` trait will be removed soon."]
14081422
pub trait Zero: Add<Self, Self> {
14091423
#[deprecated = "Use `Int::zero()` or `Float::zero()`."]

branches/auto/src/libcoretest/num/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ mod u64;
2424
mod uint;
2525

2626
/// Helper function for testing numeric operations
27-
pub fn test_num<T:Num + NumCast + ::std::fmt::Show>(ten: T, two: T) {
27+
pub fn test_num<T: Int + ::std::fmt::Show>(ten: T, two: T) {
2828
assert_eq!(ten.add(&two), cast(12i).unwrap());
2929
assert_eq!(ten.sub(&two), cast(8i).unwrap());
3030
assert_eq!(ten.mul(&two), cast(20i).unwrap());

branches/auto/src/libstd/num/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ pub fn abs_sub<T: FloatMath>(x: T, y: T) -> T {
135135

136136
/// Helper function for testing numeric operations
137137
#[cfg(test)]
138-
pub fn test_num<T:Num + NumCast + Show>(ten: T, two: T) {
138+
pub fn test_num<T: Int + Show>(ten: T, two: T) {
139139
assert_eq!(ten.add(&two), cast(12i).unwrap());
140140
assert_eq!(ten.sub(&two), cast(8i).unwrap());
141141
assert_eq!(ten.mul(&two), cast(20i).unwrap());

branches/auto/src/libstd/num/strconv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ fn int_to_str_bytes_common<T: Int>(num: T, radix: uint, sign: SignFormat, f: |u8
116116
// numbers [-35 .. 0] we always have [0 .. 35].
117117
let current_digit_signed = deccum % radix_gen;
118118
let current_digit = if current_digit_signed < _0 {
119-
-current_digit_signed
119+
_0 - current_digit_signed
120120
} else {
121121
current_digit_signed
122122
};

branches/auto/src/test/compile-fail/type-params-in-different-spaces-1.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use std::num::Num;
11+
use std::num::Int;
1212

13-
trait BrokenAdd: Num {
13+
trait BrokenAdd: Int {
1414
fn broken_add<T>(&self, rhs: T) -> Self {
1515
*self + rhs //~ ERROR expected `Self`, found `T`
1616
}
1717
}
1818

19-
impl<T: Num> BrokenAdd for T {}
19+
impl<T: Int> BrokenAdd for T {}
2020

2121
pub fn main() {
2222
let foo: u8 = 0u8;

branches/auto/src/test/run-pass/trait-inheritance-num.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
use std::cmp::{PartialEq, PartialOrd};
1313
use std::num::NumCast;
1414

15-
pub trait NumExt: Num + NumCast + PartialEq + PartialOrd {}
15+
pub trait NumExt: NumCast + PartialEq + PartialOrd {}
1616

1717
pub trait FloatExt: NumExt {}
1818

19-
fn greater_than_one<T:NumExt>(n: &T) -> bool { *n > NumCast::from(1i).unwrap() }
20-
fn greater_than_one_float<T:FloatExt>(n: &T) -> bool { *n > NumCast::from(1i).unwrap() }
19+
fn greater_than_one<T: NumExt>(n: &T) -> bool { *n > NumCast::from(1i).unwrap() }
20+
fn greater_than_one_float<T: FloatExt>(n: &T) -> bool { *n > NumCast::from(1i).unwrap() }
2121

2222
pub fn main() {}

branches/auto/src/test/run-pass/trait-inheritance-num0.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@
1111

1212
// Extending Num and using inherited static methods
1313

14+
use std::cmp::PartialOrd;
1415
use std::num::NumCast;
1516

1617
pub trait Num {
1718
fn from_int(i: int) -> Self;
1819
fn gt(&self, other: &Self) -> bool;
1920
}
2021

21-
pub trait NumExt: Num + NumCast { }
22+
pub trait NumExt: NumCast + PartialOrd { }
2223

2324
fn greater_than_one<T:NumExt>(n: &T) -> bool {
2425
n.gt(&NumCast::from(1i).unwrap())

branches/auto/src/test/run-pass/trait-inheritance-num1.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use std::cmp::PartialOrd;
1212
use std::num::NumCast;
1313

14-
pub trait NumExt: Num + NumCast + PartialOrd { }
14+
pub trait NumExt: NumCast + PartialOrd { }
1515

1616
fn greater_than_one<T:NumExt>(n: &T) -> bool {
1717
*n > NumCast::from(1i).unwrap()

branches/auto/src/test/run-pass/trait-inheritance-num2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ impl TypeExt for f32 {}
3232
impl TypeExt for f64 {}
3333

3434

35-
pub trait NumExt: TypeExt + PartialEq + PartialOrd + Num + NumCast {}
35+
pub trait NumExt: TypeExt + PartialEq + PartialOrd + NumCast {}
3636

3737
impl NumExt for u8 {}
3838
impl NumExt for u16 {}

branches/auto/src/test/run-pass/trait-inheritance-num5.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use std::cmp::PartialEq;
1212
use std::num::NumCast;
1313

14-
pub trait NumExt: PartialEq + Num + NumCast {}
14+
pub trait NumExt: PartialEq + NumCast {}
1515

1616
impl NumExt for f32 {}
1717
impl NumExt for int {}

0 commit comments

Comments
 (0)