Skip to content

Commit e965ba8

Browse files
committed
Remove lots of numeric traits from the preludes
Num, NumCast, Unsigned, Float, Primitive and Int have been removed.
1 parent 891559e commit e965ba8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+100
-66
lines changed

src/doc/guide-lifetimes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ expensive. So we'd like to define a function that takes the points just as
5151
a reference.
5252

5353
~~~
54+
# use std::num::Float;
5455
# struct Point {x: f64, y: f64}
5556
# fn sqrt(f: f64) -> f64 { 0.0 }
5657
fn compute_distance(p1: &Point, p2: &Point) -> f64 {

src/doc/guide-tasks.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ Here is another example showing how futures allow you to background
225225
computations. The workload will be distributed on the available cores.
226226

227227
```{rust}
228+
# use std::num::Float;
228229
# use std::sync::Future;
229230
fn partial_sum(start: uint) -> f64 {
230231
let mut local_sum = 0f64;
@@ -262,6 +263,7 @@ several computations on a single large vector of floats. Each task needs the
262263
full vector to perform its duty.
263264

264265
```{rust}
266+
use std::num::Float;
265267
use std::rand;
266268
use std::sync::Arc;
267269

src/libarena/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use std::cmp;
3838
use std::intrinsics::{TyDesc, get_tydesc};
3939
use std::intrinsics;
4040
use std::mem;
41-
use std::num::UnsignedInt;
41+
use std::num::{Int, UnsignedInt};
4242
use std::ptr;
4343
use std::rc::Rc;
4444
use std::rt::heap::{allocate, deallocate};

src/libcollections/bit.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
//!
2323
//! ```
2424
//! use std::collections::{BitvSet, Bitv};
25+
//! use std::num::Float;
2526
//! use std::iter;
2627
//!
2728
//! let max_prime = 10000;
@@ -69,6 +70,7 @@ use core::default::Default;
6970
use core::fmt;
7071
use core::iter::{Chain, Enumerate, Repeat, Skip, Take};
7172
use core::iter;
73+
use core::num::Int;
7274
use core::slice;
7375
use core::u32;
7476
use std::hash;

src/libcollections/enum_set.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
1616
use core::prelude::*;
1717
use core::fmt;
18+
use core::num::Int;
1819

1920
// FIXME(contentions): implement union family of methods? (general design may be wrong here)
2021

src/libcollections/hash/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ use alloc::boxed::Box;
6969
use alloc::rc::Rc;
7070
use core::intrinsics::TypeId;
7171
use core::mem;
72+
use core::num::Int;
7273

7374
use vec::Vec;
7475

src/libcollections/vec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use core::default::Default;
2121
use core::fmt;
2222
use core::kinds::marker::{ContravariantLifetime, InvariantType};
2323
use core::mem;
24-
use core::num::UnsignedInt;
24+
use core::num::{Int, UnsignedInt};
2525
use core::ops;
2626
use core::ptr;
2727
use core::raw::Slice as RawSlice;

src/libcore/num/f32.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ impl Float for f32 {
234234
/// The fractional part of the number, satisfying:
235235
///
236236
/// ```rust
237+
/// use core::num::Float;
238+
///
237239
/// let x = 1.65f32;
238240
/// assert!(x == x.trunc() + x.fract())
239241
/// ```

src/libcore/num/f64.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,8 @@ impl Float for f64 {
240240
/// The fractional part of the number, satisfying:
241241
///
242242
/// ```rust
243+
/// use core::num::Float;
244+
///
243245
/// let x = 1.65f64;
244246
/// assert!(x == x.trunc() + x.fract())
245247
/// ```

src/libcore/num/mod.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ pub trait Int
204204
/// # Example
205205
///
206206
/// ```rust
207+
/// use std::num::Int;
208+
///
207209
/// let n = 0b01001100u8;
208210
///
209211
/// assert_eq!(n.count_ones(), 3);
@@ -215,6 +217,8 @@ pub trait Int
215217
/// # Example
216218
///
217219
/// ```rust
220+
/// use std::num::Int;
221+
///
218222
/// let n = 0b01001100u8;
219223
///
220224
/// assert_eq!(n.count_zeros(), 5);
@@ -230,6 +234,8 @@ pub trait Int
230234
/// # Example
231235
///
232236
/// ```rust
237+
/// use std::num::Int;
238+
///
233239
/// let n = 0b0101000u16;
234240
///
235241
/// assert_eq!(n.leading_zeros(), 10);
@@ -242,6 +248,8 @@ pub trait Int
242248
/// # Example
243249
///
244250
/// ```rust
251+
/// use std::num::Int;
252+
///
245253
/// let n = 0b0101000u16;
246254
///
247255
/// assert_eq!(n.trailing_zeros(), 3);
@@ -254,6 +262,8 @@ pub trait Int
254262
/// # Example
255263
///
256264
/// ```rust
265+
/// use std::num::Int;
266+
///
257267
/// let n = 0x0123456789ABCDEFu64;
258268
/// let m = 0x3456789ABCDEF012u64;
259269
///
@@ -267,6 +277,8 @@ pub trait Int
267277
/// # Example
268278
///
269279
/// ```rust
280+
/// use std::num::Int;
281+
///
270282
/// let n = 0x0123456789ABCDEFu64;
271283
/// let m = 0xDEF0123456789ABCu64;
272284
///
@@ -279,6 +291,8 @@ pub trait Int
279291
/// # Example
280292
///
281293
/// ```rust
294+
/// use std::num::Int;
295+
///
282296
/// let n = 0x0123456789ABCDEFu64;
283297
/// let m = 0xEFCDAB8967452301u64;
284298
///
@@ -293,6 +307,8 @@ pub trait Int
293307
/// # Example
294308
///
295309
/// ```rust
310+
/// use std::num::Int;
311+
///
296312
/// let n = 0x0123456789ABCDEFu64;
297313
///
298314
/// if cfg!(target_endian = "big") {
@@ -313,6 +329,8 @@ pub trait Int
313329
/// # Example
314330
///
315331
/// ```rust
332+
/// use std::num::Int;
333+
///
316334
/// let n = 0x0123456789ABCDEFu64;
317335
///
318336
/// if cfg!(target_endian = "little") {
@@ -333,6 +351,8 @@ pub trait Int
333351
/// # Example
334352
///
335353
/// ```rust
354+
/// use std::num::Int;
355+
///
336356
/// let n = 0x0123456789ABCDEFu64;
337357
///
338358
/// if cfg!(target_endian = "big") {
@@ -353,6 +373,8 @@ pub trait Int
353373
/// # Example
354374
///
355375
/// ```rust
376+
/// use std::num::Int;
377+
///
356378
/// let n = 0x0123456789ABCDEFu64;
357379
///
358380
/// if cfg!(target_endian = "little") {

src/libcore/prelude.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ pub use cmp::{Ordering, Less, Equal, Greater, Equiv};
5151
pub use iter::{FromIterator, Extend};
5252
pub use iter::{Iterator, DoubleEndedIterator, RandomAccessIterator, CloneableIterator};
5353
pub use iter::{OrdIterator, MutableDoubleEndedIterator, ExactSize};
54-
pub use num::{Num, NumCast};
55-
pub use num::{Signed, Unsigned, Float};
56-
pub use num::{Primitive, Int, ToPrimitive, FromPrimitive};
54+
pub use num::{Signed, ToPrimitive, FromPrimitive};
5755
pub use option::{Option, Some, None};
5856
pub use ptr::RawPtr;
5957
pub use result::{Result, Ok, Err};

src/libcoretest/iter.rs

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use core::iter::*;
1212
use core::iter::order::*;
1313
use core::uint;
1414
use core::cmp;
15-
use core::num;
1615
use core::ops::Slice;
1716

1817
use test::Bencher;
@@ -689,50 +688,6 @@ fn test_double_ended_range() {
689688

690689
#[test]
691690
fn test_range() {
692-
/// A mock type to check Range when ToPrimitive returns None
693-
struct Foo;
694-
695-
impl ToPrimitive for Foo {
696-
fn to_i64(&self) -> Option<i64> { None }
697-
fn to_u64(&self) -> Option<u64> { None }
698-
}
699-
700-
impl Add<Foo, Foo> for Foo {
701-
fn add(&self, _: &Foo) -> Foo {
702-
Foo
703-
}
704-
}
705-
706-
impl PartialEq for Foo {
707-
fn eq(&self, _: &Foo) -> bool {
708-
true
709-
}
710-
}
711-
712-
impl PartialOrd for Foo {
713-
fn partial_cmp(&self, _: &Foo) -> Option<Ordering> {
714-
None
715-
}
716-
}
717-
718-
impl Clone for Foo {
719-
fn clone(&self) -> Foo {
720-
Foo
721-
}
722-
}
723-
724-
impl Mul<Foo, Foo> for Foo {
725-
fn mul(&self, _: &Foo) -> Foo {
726-
Foo
727-
}
728-
}
729-
730-
impl num::One for Foo {
731-
fn one() -> Foo {
732-
Foo
733-
}
734-
}
735-
736691
assert!(range(0i, 5).collect::<Vec<int>>() == vec![0i, 1, 2, 3, 4]);
737692
assert!(range(-10i, -1).collect::<Vec<int>>() ==
738693
vec![-10, -9, -8, -7, -6, -5, -4, -3, -2]);
@@ -746,7 +701,6 @@ fn test_range() {
746701
// this test is only meaningful when sizeof uint < sizeof u64
747702
assert_eq!(range(uint::MAX - 1, uint::MAX).size_hint(), (1, Some(1)));
748703
assert_eq!(range(-10i, -1).size_hint(), (9, Some(9)));
749-
assert_eq!(range(Foo, Foo).size_hint(), (0, None));
750704
}
751705

752706
#[test]

src/libcoretest/num/int_macros.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ macro_rules! int_module (($T:ty, $T_i:ident) => (
1515
mod tests {
1616
use core::$T_i::*;
1717
use core::int;
18+
use core::num::Int;
1819
use num;
1920

2021
#[test]

src/libcoretest/num/mod.rs

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

11-
use core::num::cast;
11+
use core::cmp::PartialEq;
12+
use core::fmt::Show;
13+
use core::num::{NumCast, cast};
14+
use core::ops::{Add, Sub, Mul, Div, Rem};
1215

1316
mod int_macros;
1417
mod i8;
@@ -24,7 +27,12 @@ mod u64;
2427
mod uint;
2528

2629
/// Helper function for testing numeric operations
27-
pub fn test_num<T: Int + ::std::fmt::Show>(ten: T, two: T) {
30+
pub fn test_num<T>(ten: T, two: T) where
31+
T: PartialEq + NumCast
32+
+ Add<T, T> + Sub<T, T>
33+
+ Mul<T, T> + Div<T, T>
34+
+ Rem<T, T> + Show
35+
{
2836
assert_eq!(ten.add(&two), cast(12i).unwrap());
2937
assert_eq!(ten.sub(&two), cast(8i).unwrap());
3038
assert_eq!(ten.mul(&two), cast(20i).unwrap());

src/libcoretest/num/uint_macros.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ macro_rules! uint_module (($T:ty, $T_i:ident) => (
1414
#[cfg(test)]
1515
mod tests {
1616
use core::$T_i::*;
17+
use core::num::Int;
1718
use num;
1819

1920
#[test]

src/librand/chacha.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//! The ChaCha random number generator.
1212
1313
use core::prelude::*;
14+
use core::num::Int;
1415

1516
use {Rng, SeedableRng, Rand};
1617

src/librand/distributions/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ that do not need to record state.
2323
#![experimental]
2424

2525
use core::prelude::*;
26+
use core::num::Int;
2627

2728
use {Rng, Rand};
2829

src/librand/distributions/range.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// this is surprisingly complicated to be both generic & correct
1414

1515
use core::prelude::*;
16+
use core::num::Int;
1617

1718
use Rng;
1819
use distributions::{Sample, IndependentSample};
@@ -162,6 +163,7 @@ float_impl! { f64 }
162163

163164
#[cfg(test)]
164165
mod tests {
166+
use std::num::Int;
165167
use std::prelude::*;
166168
use distributions::{Sample, IndependentSample};
167169
use super::Range;

src/librbml/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,11 @@ pub enum Error {
114114
pub mod reader {
115115
use std::char;
116116

117-
use std::mem::transmute;
118117
use std::int;
119-
use std::option::{None, Option, Some};
120118
use std::io::extensions::u64_from_be_bytes;
119+
use std::mem::transmute;
120+
use std::num::Int;
121+
use std::option::{None, Option, Some};
121122

122123
use serialize;
123124

src/librustc/back/lto.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use flate;
2323

2424
use std::iter;
2525
use std::mem;
26+
use std::num::Int;
2627

2728
pub fn run(sess: &session::Session, llmod: ModuleRef,
2829
tm: TargetMachineRef, reachable: &[String]) {

src/librustc/middle/check_match.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use middle::ty;
2121
use std::fmt;
2222
use std::iter::AdditiveIterator;
2323
use std::iter::range_inclusive;
24+
use std::num::Float;
2425
use std::slice;
2526
use syntax::ast::*;
2627
use syntax::ast_util::walk_pat;

src/librustc/middle/trans/type_of.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use util::ppaux::Repr;
2121

2222
use middle::trans::type_::Type;
2323

24+
use std::num::Int;
2425
use syntax::abi;
2526
use syntax::ast;
2627

src/librustc_back/sha2.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#![allow(deprecated)] // to_be32
1616

1717
use std::iter::range_step;
18+
use std::num::Int;
1819
use std::slice::bytes::{MutableByteVector, copy_memory};
1920
use serialize::hex::ToHex;
2021

@@ -530,6 +531,7 @@ mod tests {
530531
use self::rand::isaac::IsaacRng;
531532
use self::rand::Rng;
532533
use serialize::hex::FromHex;
534+
use std::num::Int;
533535

534536
// A normal addition - no overflow occurs
535537
#[test]

0 commit comments

Comments
 (0)