diff options
| author | Brendan Zabarauskas <bjzaba@yahoo.com.au> | 2014-11-10 16:26:10 +1100 |
|---|---|---|
| committer | Brendan Zabarauskas <bjzaba@yahoo.com.au> | 2014-11-13 03:46:03 +1100 |
| commit | e965ba85ca689ad77f63b7f0af9d7e337dcb4825 (patch) | |
| tree | 0ecf2223970c18455595e523ca594fe6d3321129 | |
| parent | 891559e30d045606aa109f4991074f783a5e50f8 (diff) | |
| download | rust-e965ba85ca689ad77f63b7f0af9d7e337dcb4825.tar.gz rust-e965ba85ca689ad77f63b7f0af9d7e337dcb4825.zip | |
Remove lots of numeric traits from the preludes
Num, NumCast, Unsigned, Float, Primitive and Int have been removed.
48 files changed, 100 insertions, 66 deletions
diff --git a/src/doc/guide-lifetimes.md b/src/doc/guide-lifetimes.md index b6ea1ddb394..e3c050f0e90 100644 --- a/src/doc/guide-lifetimes.md +++ b/src/doc/guide-lifetimes.md @@ -51,6 +51,7 @@ expensive. So we'd like to define a function that takes the points just as a reference. ~~~ +# use std::num::Float; # struct Point {x: f64, y: f64} # fn sqrt(f: f64) -> f64 { 0.0 } fn compute_distance(p1: &Point, p2: &Point) -> f64 { diff --git a/src/doc/guide-tasks.md b/src/doc/guide-tasks.md index 4eaca64560c..c2309ba479e 100644 --- a/src/doc/guide-tasks.md +++ b/src/doc/guide-tasks.md @@ -225,6 +225,7 @@ Here is another example showing how futures allow you to background computations. The workload will be distributed on the available cores. ```{rust} +# use std::num::Float; # use std::sync::Future; fn partial_sum(start: uint) -> f64 { let mut local_sum = 0f64; @@ -262,6 +263,7 @@ several computations on a single large vector of floats. Each task needs the full vector to perform its duty. ```{rust} +use std::num::Float; use std::rand; use std::sync::Arc; diff --git a/src/libarena/lib.rs b/src/libarena/lib.rs index 1e9ab34b0ac..33d4406b733 100644 --- a/src/libarena/lib.rs +++ b/src/libarena/lib.rs @@ -38,7 +38,7 @@ use std::cmp; use std::intrinsics::{TyDesc, get_tydesc}; use std::intrinsics; use std::mem; -use std::num::UnsignedInt; +use std::num::{Int, UnsignedInt}; use std::ptr; use std::rc::Rc; use std::rt::heap::{allocate, deallocate}; diff --git a/src/libcollections/bit.rs b/src/libcollections/bit.rs index 6ed9dad6252..bfb5a010ed8 100644 --- a/src/libcollections/bit.rs +++ b/src/libcollections/bit.rs @@ -22,6 +22,7 @@ //! //! ``` //! use std::collections::{BitvSet, Bitv}; +//! use std::num::Float; //! use std::iter; //! //! let max_prime = 10000; @@ -69,6 +70,7 @@ use core::default::Default; use core::fmt; use core::iter::{Chain, Enumerate, Repeat, Skip, Take}; use core::iter; +use core::num::Int; use core::slice; use core::u32; use std::hash; diff --git a/src/libcollections/enum_set.rs b/src/libcollections/enum_set.rs index cc858103764..ac8e45f9f94 100644 --- a/src/libcollections/enum_set.rs +++ b/src/libcollections/enum_set.rs @@ -15,6 +15,7 @@ use core::prelude::*; use core::fmt; +use core::num::Int; // FIXME(contentions): implement union family of methods? (general design may be wrong here) diff --git a/src/libcollections/hash/mod.rs b/src/libcollections/hash/mod.rs index 43faaac3952..6082a0ca013 100644 --- a/src/libcollections/hash/mod.rs +++ b/src/libcollections/hash/mod.rs @@ -69,6 +69,7 @@ use alloc::boxed::Box; use alloc::rc::Rc; use core::intrinsics::TypeId; use core::mem; +use core::num::Int; use vec::Vec; diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 9f51c6d1b5e..4fad6081a93 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -21,7 +21,7 @@ use core::default::Default; use core::fmt; use core::kinds::marker::{ContravariantLifetime, InvariantType}; use core::mem; -use core::num::UnsignedInt; +use core::num::{Int, UnsignedInt}; use core::ops; use core::ptr; use core::raw::Slice as RawSlice; diff --git a/src/libcore/num/f32.rs b/src/libcore/num/f32.rs index fddb41c38ef..5913b8d75a7 100644 --- a/src/libcore/num/f32.rs +++ b/src/libcore/num/f32.rs @@ -234,6 +234,8 @@ impl Float for f32 { /// The fractional part of the number, satisfying: /// /// ```rust + /// use core::num::Float; + /// /// let x = 1.65f32; /// assert!(x == x.trunc() + x.fract()) /// ``` diff --git a/src/libcore/num/f64.rs b/src/libcore/num/f64.rs index f06b7e97cf1..8f68578d768 100644 --- a/src/libcore/num/f64.rs +++ b/src/libcore/num/f64.rs @@ -240,6 +240,8 @@ impl Float for f64 { /// The fractional part of the number, satisfying: /// /// ```rust + /// use core::num::Float; + /// /// let x = 1.65f64; /// assert!(x == x.trunc() + x.fract()) /// ``` diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 6ec6839f0a0..dd2ee6e01c6 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -204,6 +204,8 @@ pub trait Int /// # Example /// /// ```rust + /// use std::num::Int; + /// /// let n = 0b01001100u8; /// /// assert_eq!(n.count_ones(), 3); @@ -215,6 +217,8 @@ pub trait Int /// # Example /// /// ```rust + /// use std::num::Int; + /// /// let n = 0b01001100u8; /// /// assert_eq!(n.count_zeros(), 5); @@ -230,6 +234,8 @@ pub trait Int /// # Example /// /// ```rust + /// use std::num::Int; + /// /// let n = 0b0101000u16; /// /// assert_eq!(n.leading_zeros(), 10); @@ -242,6 +248,8 @@ pub trait Int /// # Example /// /// ```rust + /// use std::num::Int; + /// /// let n = 0b0101000u16; /// /// assert_eq!(n.trailing_zeros(), 3); @@ -254,6 +262,8 @@ pub trait Int /// # Example /// /// ```rust + /// use std::num::Int; + /// /// let n = 0x0123456789ABCDEFu64; /// let m = 0x3456789ABCDEF012u64; /// @@ -267,6 +277,8 @@ pub trait Int /// # Example /// /// ```rust + /// use std::num::Int; + /// /// let n = 0x0123456789ABCDEFu64; /// let m = 0xDEF0123456789ABCu64; /// @@ -279,6 +291,8 @@ pub trait Int /// # Example /// /// ```rust + /// use std::num::Int; + /// /// let n = 0x0123456789ABCDEFu64; /// let m = 0xEFCDAB8967452301u64; /// @@ -293,6 +307,8 @@ pub trait Int /// # Example /// /// ```rust + /// use std::num::Int; + /// /// let n = 0x0123456789ABCDEFu64; /// /// if cfg!(target_endian = "big") { @@ -313,6 +329,8 @@ pub trait Int /// # Example /// /// ```rust + /// use std::num::Int; + /// /// let n = 0x0123456789ABCDEFu64; /// /// if cfg!(target_endian = "little") { @@ -333,6 +351,8 @@ pub trait Int /// # Example /// /// ```rust + /// use std::num::Int; + /// /// let n = 0x0123456789ABCDEFu64; /// /// if cfg!(target_endian = "big") { @@ -353,6 +373,8 @@ pub trait Int /// # Example /// /// ```rust + /// use std::num::Int; + /// /// let n = 0x0123456789ABCDEFu64; /// /// if cfg!(target_endian = "little") { diff --git a/src/libcore/prelude.rs b/src/libcore/prelude.rs index 045aca8aa0a..7e35f20f078 100644 --- a/src/libcore/prelude.rs +++ b/src/libcore/prelude.rs @@ -51,9 +51,7 @@ pub use cmp::{Ordering, Less, Equal, Greater, Equiv}; pub use iter::{FromIterator, Extend}; pub use iter::{Iterator, DoubleEndedIterator, RandomAccessIterator, CloneableIterator}; pub use iter::{OrdIterator, MutableDoubleEndedIterator, ExactSize}; -pub use num::{Num, NumCast}; -pub use num::{Signed, Unsigned, Float}; -pub use num::{Primitive, Int, ToPrimitive, FromPrimitive}; +pub use num::{Signed, ToPrimitive, FromPrimitive}; pub use option::{Option, Some, None}; pub use ptr::RawPtr; pub use result::{Result, Ok, Err}; diff --git a/src/libcoretest/iter.rs b/src/libcoretest/iter.rs index 7e7e11a3645..3bb8d735d9c 100644 --- a/src/libcoretest/iter.rs +++ b/src/libcoretest/iter.rs @@ -12,7 +12,6 @@ use core::iter::*; use core::iter::order::*; use core::uint; use core::cmp; -use core::num; use core::ops::Slice; use test::Bencher; @@ -689,50 +688,6 @@ fn test_double_ended_range() { #[test] fn test_range() { - /// A mock type to check Range when ToPrimitive returns None - struct Foo; - - impl ToPrimitive for Foo { - fn to_i64(&self) -> Option<i64> { None } - fn to_u64(&self) -> Option<u64> { None } - } - - impl Add<Foo, Foo> for Foo { - fn add(&self, _: &Foo) -> Foo { - Foo - } - } - - impl PartialEq for Foo { - fn eq(&self, _: &Foo) -> bool { - true - } - } - - impl PartialOrd for Foo { - fn partial_cmp(&self, _: &Foo) -> Option<Ordering> { - None - } - } - - impl Clone for Foo { - fn clone(&self) -> Foo { - Foo - } - } - - impl Mul<Foo, Foo> for Foo { - fn mul(&self, _: &Foo) -> Foo { - Foo - } - } - - impl num::One for Foo { - fn one() -> Foo { - Foo - } - } - assert!(range(0i, 5).collect::<Vec<int>>() == vec![0i, 1, 2, 3, 4]); assert!(range(-10i, -1).collect::<Vec<int>>() == vec![-10, -9, -8, -7, -6, -5, -4, -3, -2]); @@ -746,7 +701,6 @@ fn test_range() { // this test is only meaningful when sizeof uint < sizeof u64 assert_eq!(range(uint::MAX - 1, uint::MAX).size_hint(), (1, Some(1))); assert_eq!(range(-10i, -1).size_hint(), (9, Some(9))); - assert_eq!(range(Foo, Foo).size_hint(), (0, None)); } #[test] diff --git a/src/libcoretest/num/int_macros.rs b/src/libcoretest/num/int_macros.rs index 51af2e2916d..a1b096bf454 100644 --- a/src/libcoretest/num/int_macros.rs +++ b/src/libcoretest/num/int_macros.rs @@ -15,6 +15,7 @@ macro_rules! int_module (($T:ty, $T_i:ident) => ( mod tests { use core::$T_i::*; use core::int; + use core::num::Int; use num; #[test] diff --git a/src/libcoretest/num/mod.rs b/src/libcoretest/num/mod.rs index 51a44ef4d59..38502321c1d 100644 --- a/src/libcoretest/num/mod.rs +++ b/src/libcoretest/num/mod.rs @@ -8,7 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use core::num::cast; +use core::cmp::PartialEq; +use core::fmt::Show; +use core::num::{NumCast, cast}; +use core::ops::{Add, Sub, Mul, Div, Rem}; mod int_macros; mod i8; @@ -24,7 +27,12 @@ mod u64; mod uint; /// Helper function for testing numeric operations -pub fn test_num<T: Int + ::std::fmt::Show>(ten: T, two: T) { +pub fn test_num<T>(ten: T, two: T) where + T: PartialEq + NumCast + + Add<T, T> + Sub<T, T> + + Mul<T, T> + Div<T, T> + + Rem<T, T> + Show +{ assert_eq!(ten.add(&two), cast(12i).unwrap()); assert_eq!(ten.sub(&two), cast(8i).unwrap()); assert_eq!(ten.mul(&two), cast(20i).unwrap()); diff --git a/src/libcoretest/num/uint_macros.rs b/src/libcoretest/num/uint_macros.rs index 1d3f1718d72..01a88119b64 100644 --- a/src/libcoretest/num/uint_macros.rs +++ b/src/libcoretest/num/uint_macros.rs @@ -14,6 +14,7 @@ macro_rules! uint_module (($T:ty, $T_i:ident) => ( #[cfg(test)] mod tests { use core::$T_i::*; + use core::num::Int; use num; #[test] diff --git a/src/librand/chacha.rs b/src/librand/chacha.rs index 97e68bcbb2c..2693f183644 100644 --- a/src/librand/chacha.rs +++ b/src/librand/chacha.rs @@ -11,6 +11,7 @@ //! The ChaCha random number generator. use core::prelude::*; +use core::num::Int; use {Rng, SeedableRng, Rand}; diff --git a/src/librand/distributions/mod.rs b/src/librand/distributions/mod.rs index 26d5d3fb2f9..73817a52fa7 100644 --- a/src/librand/distributions/mod.rs +++ b/src/librand/distributions/mod.rs @@ -23,6 +23,7 @@ that do not need to record state. #![experimental] use core::prelude::*; +use core::num::Int; use {Rng, Rand}; diff --git a/src/librand/distributions/range.rs b/src/librand/distributions/range.rs index e2762759e5e..03270ff3c60 100644 --- a/src/librand/distributions/range.rs +++ b/src/librand/distributions/range.rs @@ -13,6 +13,7 @@ // this is surprisingly complicated to be both generic & correct use core::prelude::*; +use core::num::Int; use Rng; use distributions::{Sample, IndependentSample}; @@ -162,6 +163,7 @@ float_impl! { f64 } #[cfg(test)] mod tests { + use std::num::Int; use std::prelude::*; use distributions::{Sample, IndependentSample}; use super::Range; diff --git a/src/librbml/lib.rs b/src/librbml/lib.rs index 1dfc0d970a9..90cd7920e68 100644 --- a/src/librbml/lib.rs +++ b/src/librbml/lib.rs @@ -114,10 +114,11 @@ pub enum Error { pub mod reader { use std::char; - use std::mem::transmute; use std::int; - use std::option::{None, Option, Some}; use std::io::extensions::u64_from_be_bytes; + use std::mem::transmute; + use std::num::Int; + use std::option::{None, Option, Some}; use serialize; diff --git a/src/librustc/back/lto.rs b/src/librustc/back/lto.rs index 58db79f41ca..3fbf830485b 100644 --- a/src/librustc/back/lto.rs +++ b/src/librustc/back/lto.rs @@ -23,6 +23,7 @@ use flate; use std::iter; use std::mem; +use std::num::Int; pub fn run(sess: &session::Session, llmod: ModuleRef, tm: TargetMachineRef, reachable: &[String]) { diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index 52bb0dc0784..34b696a416d 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -21,6 +21,7 @@ use middle::ty; use std::fmt; use std::iter::AdditiveIterator; use std::iter::range_inclusive; +use std::num::Float; use std::slice; use syntax::ast::*; use syntax::ast_util::walk_pat; diff --git a/src/librustc/middle/trans/type_of.rs b/src/librustc/middle/trans/type_of.rs index 5e2df42d2d6..a597325015c 100644 --- a/src/librustc/middle/trans/type_of.rs +++ b/src/librustc/middle/trans/type_of.rs @@ -21,6 +21,7 @@ use util::ppaux::Repr; use middle::trans::type_::Type; +use std::num::Int; use syntax::abi; use syntax::ast; diff --git a/src/librustc_back/sha2.rs b/src/librustc_back/sha2.rs index 445279724b3..4319cd791b8 100644 --- a/src/librustc_back/sha2.rs +++ b/src/librustc_back/sha2.rs @@ -15,6 +15,7 @@ #![allow(deprecated)] // to_be32 use std::iter::range_step; +use std::num::Int; use std::slice::bytes::{MutableByteVector, copy_memory}; use serialize::hex::ToHex; @@ -530,6 +531,7 @@ mod tests { use self::rand::isaac::IsaacRng; use self::rand::Rng; use serialize::hex::FromHex; + use std::num::Int; // A normal addition - no overflow occurs #[test] diff --git a/src/libserialize/json.rs b/src/libserialize/json.rs index 837784da6df..626535f989e 100644 --- a/src/libserialize/json.rs +++ b/src/libserialize/json.rs @@ -199,7 +199,7 @@ use std::collections::{HashMap, TreeMap}; use std::{char, f64, fmt, io, num, str}; use std::io::MemWriter; use std::mem::{swap, transmute}; -use std::num::{FPNaN, FPInfinite}; +use std::num::{Float, FPNaN, FPInfinite, Int}; use std::str::ScalarValue; use std::string; use std::vec::Vec; @@ -2455,6 +2455,7 @@ mod tests { TrailingCharacters, TrailingComma}; use std::{i64, u64, f32, f64, io}; use std::collections::TreeMap; + use std::num::Float; use std::string; #[deriving(Decodable, Eq, PartialEq, Show)] diff --git a/src/libstd/fmt.rs b/src/libstd/fmt.rs index 782ef098d81..eb81935a8c9 100644 --- a/src/libstd/fmt.rs +++ b/src/libstd/fmt.rs @@ -190,6 +190,7 @@ like: ```rust use std::fmt; use std::f64; +use std::num::Float; struct Vector2D { x: int, diff --git a/src/libstd/num/f32.rs b/src/libstd/num/f32.rs index c72b8205f19..3f46cc8af50 100644 --- a/src/libstd/num/f32.rs +++ b/src/libstd/num/f32.rs @@ -20,6 +20,7 @@ use prelude::*; use from_str::FromStr; use intrinsics; use libc::c_int; +use num::{Float, FloatMath}; use num::strconv; use num; diff --git a/src/libstd/num/f64.rs b/src/libstd/num/f64.rs index 311fd0e87a3..4d691fc9676 100644 --- a/src/libstd/num/f64.rs +++ b/src/libstd/num/f64.rs @@ -19,6 +19,7 @@ use prelude::*; use from_str::FromStr; use intrinsics; use libc::c_int; +use num::{Float, FloatMath}; use num::strconv; use num; diff --git a/src/libstd/num/mod.rs b/src/libstd/num/mod.rs index 28fe7538ca5..62e70e0c9de 100644 --- a/src/libstd/num/mod.rs +++ b/src/libstd/num/mod.rs @@ -18,7 +18,9 @@ use option::Option; +#[cfg(test)] use cmp::PartialEq; #[cfg(test)] use fmt::Show; +#[cfg(test)] use ops::{Add, Sub, Mul, Div, Rem}; pub use core::num::{Num, div_rem, Zero, zero, One, one}; pub use core::num::{Signed, abs, signum}; @@ -135,7 +137,12 @@ pub fn abs_sub<T: FloatMath>(x: T, y: T) -> T { /// Helper function for testing numeric operations #[cfg(test)] -pub fn test_num<T: Int + Show>(ten: T, two: T) { +pub fn test_num<T>(ten: T, two: T) where + T: PartialEq + NumCast + + Add<T, T> + Sub<T, T> + + Mul<T, T> + Div<T, T> + + Rem<T, T> + Show +{ assert_eq!(ten.add(&two), cast(12i).unwrap()); assert_eq!(ten.sub(&two), cast(8i).unwrap()); assert_eq!(ten.mul(&two), cast(20i).unwrap()); diff --git a/src/libstd/prelude.rs b/src/libstd/prelude.rs index 3c20d205b77..0baae850eaa 100644 --- a/src/libstd/prelude.rs +++ b/src/libstd/prelude.rs @@ -67,9 +67,7 @@ #[doc(no_inline)] pub use iter::{Iterator, DoubleEndedIterator}; #[doc(no_inline)] pub use iter::{RandomAccessIterator, CloneableIterator}; #[doc(no_inline)] pub use iter::{OrdIterator, MutableDoubleEndedIterator}; -#[doc(no_inline)] pub use num::{Num, NumCast}; -#[doc(no_inline)] pub use num::{Signed, Unsigned, Primitive, Int, Float}; -#[doc(no_inline)] pub use num::{FloatMath, ToPrimitive, FromPrimitive}; +#[doc(no_inline)] pub use num::{Signed, ToPrimitive, FromPrimitive}; #[doc(no_inline)] pub use boxed::Box; #[doc(no_inline)] pub use option::{Option, Some, None}; #[doc(no_inline)] pub use path::{GenericPath, Path, PosixPath, WindowsPath}; diff --git a/src/libstd/rand/reader.rs b/src/libstd/rand/reader.rs index c8ed9805215..ab3216e93a0 100644 --- a/src/libstd/rand/reader.rs +++ b/src/libstd/rand/reader.rs @@ -78,6 +78,7 @@ mod test { use super::ReaderRng; use io::MemReader; + use num::Int; use rand::Rng; #[test] diff --git a/src/libstd/sys/common/mod.rs b/src/libstd/sys/common/mod.rs index 65eb987afea..cacb128faa5 100644 --- a/src/libstd/sys/common/mod.rs +++ b/src/libstd/sys/common/mod.rs @@ -15,6 +15,7 @@ use io::{mod, IoError, IoResult}; use prelude::*; use sys::{last_error, retry, fs}; use c_str::CString; +use num::Int; use path::BytesContainer; use collections; diff --git a/src/libstd/sys/common/net.rs b/src/libstd/sys/common/net.rs index 7c44142d93c..7bb3c6b0ec9 100644 --- a/src/libstd/sys/common/net.rs +++ b/src/libstd/sys/common/net.rs @@ -11,6 +11,7 @@ use alloc::arc::Arc; use libc::{mod, c_char, c_int}; use mem; +use num::Int; use ptr::{mod, null, null_mut}; use rt::mutex; use io::net::ip::{SocketAddr, IpAddr, Ipv4Addr, Ipv6Addr}; diff --git a/src/libstd/sys/unix/mod.rs b/src/libstd/sys/unix/mod.rs index 939ae79facf..969570d385c 100644 --- a/src/libstd/sys/unix/mod.rs +++ b/src/libstd/sys/unix/mod.rs @@ -18,6 +18,7 @@ extern crate libc; use num; +use num::Int; use prelude::*; use io::{mod, IoResult, IoError}; use sys_common::mkerr_libc; diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index c21f34dcab0..bf5f7ff9ad3 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -20,6 +20,7 @@ use ptr::P; use std::fmt; use std::fmt::Show; +use std::num::Int; use std::rc::Rc; use serialize::{Encodable, Decodable, Encoder, Decoder}; diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 0f364d1ba0b..51738ece80f 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -20,6 +20,7 @@ use ptr::P; use std::cell::{Cell, RefCell}; use std::io::File; use std::rc::Rc; +use std::num::Int; use std::str; use std::iter; diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 6873c015fd5..aab7c1b2178 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -87,6 +87,7 @@ use std::collections::HashSet; use std::io::fs::PathExtensions; use std::mem::replace; use std::mem; +use std::num::Float; use std::rc::Rc; use std::iter; diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index ee678641429..a25aff3eaff 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -60,6 +60,7 @@ use std::io::fs::PathExtensions; use std::io::stdio::StdWriter; use std::io::{File, ChanReader, ChanWriter}; use std::io; +use std::num::{Int, FloatMath}; use std::os; use std::string::String; use std::task::TaskBuilder; diff --git a/src/libtest/stats.rs b/src/libtest/stats.rs index 6be5bca552d..5cec5076e06 100644 --- a/src/libtest/stats.rs +++ b/src/libtest/stats.rs @@ -16,6 +16,7 @@ use std::fmt::Show; use std::hash::Hash; use std::io; use std::mem; +use std::num::{Float, FloatMath}; fn local_cmp<T:Float>(x: T, y: T) -> Ordering { // arbitrarily decide that NaNs are larger than everything. @@ -1042,11 +1043,11 @@ mod tests { } #[test] fn test_sum_f64s() { - assert_eq!([0.5f64, 3.2321f64, 1.5678f64].sum(0.0), 5.2999); + assert_eq!([0.5f64, 3.2321f64, 1.5678f64].sum(), 5.2999); } #[test] fn test_sum_f64_between_ints_that_sum_to_0() { - assert_eq!([1e30f64, 1.2f64, -1e30f64].sum(0.0), 1.2); + assert_eq!([1e30f64, 1.2f64, -1e30f64].sum(), 1.2); } } @@ -1058,7 +1059,7 @@ mod bench { #[bench] pub fn sum_three_items(b: &mut Bencher) { b.iter(|| { - [1e20f64, 1.5f64, -1e20f64].sum(0.0); + [1e20f64, 1.5f64, -1e20f64].sum(); }) } #[bench] @@ -1067,7 +1068,7 @@ mod bench { let v = Vec::from_fn(500, |i| nums[i%5]); b.iter(|| { - v.as_slice().sum(0.0); + v.as_slice().sum(); }) } } diff --git a/src/test/bench/noise.rs b/src/test/bench/noise.rs index 19ccf1b6caf..4ad77a695dd 100644 --- a/src/test/bench/noise.rs +++ b/src/test/bench/noise.rs @@ -13,6 +13,7 @@ // ignore-lexer-test FIXME #15679 use std::f32::consts::PI; +use std::num::{Float, FloatMath}; use std::rand::{Rng, StdRng}; struct Vec2 { diff --git a/src/test/bench/shootout-fasta.rs b/src/test/bench/shootout-fasta.rs index e61ed474504..f9fafa977ac 100644 --- a/src/test/bench/shootout-fasta.rs +++ b/src/test/bench/shootout-fasta.rs @@ -43,6 +43,7 @@ use std::io; use std::io::{BufferedWriter, File}; use std::cmp::min; +use std::num::Float; use std::os; const LINE_LENGTH: uint = 60; diff --git a/src/test/bench/shootout-k-nucleotide-pipes.rs b/src/test/bench/shootout-k-nucleotide-pipes.rs index b1cc52791ab..e40c477ec66 100644 --- a/src/test/bench/shootout-k-nucleotide-pipes.rs +++ b/src/test/bench/shootout-k-nucleotide-pipes.rs @@ -19,6 +19,7 @@ extern crate collections; use std::collections::HashMap; use std::mem::replace; +use std::num::Float; use std::option; use std::os; use std::string::String; diff --git a/src/test/bench/shootout-nbody.rs b/src/test/bench/shootout-nbody.rs index 8486fa5b034..3bcc0c25df8 100644 --- a/src/test/bench/shootout-nbody.rs +++ b/src/test/bench/shootout-nbody.rs @@ -38,6 +38,8 @@ // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED // OF THE POSSIBILITY OF SUCH DAMAGE. +use std::num::Float; + const PI: f64 = 3.141592653589793; const SOLAR_MASS: f64 = 4.0 * PI * PI; const YEAR: f64 = 365.24; diff --git a/src/test/bench/shootout-spectralnorm.rs b/src/test/bench/shootout-spectralnorm.rs index 6bf594ce15d..75f7a21ce0d 100644 --- a/src/test/bench/shootout-spectralnorm.rs +++ b/src/test/bench/shootout-spectralnorm.rs @@ -45,6 +45,7 @@ use std::iter::AdditiveIterator; use std::mem; +use std::num::Float; use std::os; use std::raw::Repr; use std::simd::f64x2; diff --git a/src/test/bench/sudoku.rs b/src/test/bench/sudoku.rs index 54824d7259f..6664eeecd5d 100644 --- a/src/test/bench/sudoku.rs +++ b/src/test/bench/sudoku.rs @@ -15,6 +15,7 @@ use std::io; use std::io::stdio::StdReader; use std::io::BufferedReader; +use std::num::Int; use std::os; // Computes a single solution to a given 9x9 sudoku diff --git a/src/test/run-pass/generic-extern-mangle.rs b/src/test/run-pass/generic-extern-mangle.rs index 69846750afc..6e3d19b05d4 100644 --- a/src/test/run-pass/generic-extern-mangle.rs +++ b/src/test/run-pass/generic-extern-mangle.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use std::num::Int; + extern "C" fn foo<T: Int>(a: T, b: T) -> T { a + b } fn main() { diff --git a/src/test/run-pass/issue-11736.rs b/src/test/run-pass/issue-11736.rs index cdd3252df4b..912a62b5b0f 100644 --- a/src/test/run-pass/issue-11736.rs +++ b/src/test/run-pass/issue-11736.rs @@ -11,6 +11,7 @@ extern crate collections; use std::collections::Bitv; +use std::num::Float; fn main() { // Generate sieve of Eratosthenes for n up to 1e6 diff --git a/src/test/run-pass/trait-inheritance-num2.rs b/src/test/run-pass/trait-inheritance-num2.rs index aa35f2cd70f..1e6e7227a06 100644 --- a/src/test/run-pass/trait-inheritance-num2.rs +++ b/src/test/run-pass/trait-inheritance-num2.rs @@ -12,6 +12,7 @@ // A more complex example of numeric extensions use std::cmp::{PartialEq, PartialOrd}; +use std::num::NumCast; pub trait TypeExt {} diff --git a/src/test/run-pass/trait-inheritance-num3.rs b/src/test/run-pass/trait-inheritance-num3.rs index 415d0a04c8b..bd93223093a 100644 --- a/src/test/run-pass/trait-inheritance-num3.rs +++ b/src/test/run-pass/trait-inheritance-num3.rs @@ -11,11 +11,11 @@ use std::cmp::{PartialEq, PartialOrd}; use std::num::NumCast; -pub trait NumExt: PartialEq + PartialOrd + Num + NumCast {} +pub trait NumExt: PartialEq + PartialOrd + NumCast {} impl NumExt for f32 {} -fn num_eq_one<T:NumExt>(n: T) { +fn num_eq_one<T: NumExt>(n: T) { println!("{}", n == NumCast::from(1i).unwrap()) } |
