From e965ba85ca689ad77f63b7f0af9d7e337dcb4825 Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Mon, 10 Nov 2014 16:26:10 +1100 Subject: [PATCH] Remove lots of numeric traits from the preludes Num, NumCast, Unsigned, Float, Primitive and Int have been removed. --- src/doc/guide-lifetimes.md | 1 + src/doc/guide-tasks.md | 2 + src/libarena/lib.rs | 2 +- src/libcollections/bit.rs | 2 + src/libcollections/enum_set.rs | 1 + src/libcollections/hash/mod.rs | 1 + src/libcollections/vec.rs | 2 +- src/libcore/num/f32.rs | 2 + src/libcore/num/f64.rs | 2 + src/libcore/num/mod.rs | 22 +++++++++ src/libcore/prelude.rs | 4 +- src/libcoretest/iter.rs | 46 ------------------- src/libcoretest/num/int_macros.rs | 1 + src/libcoretest/num/mod.rs | 12 ++++- src/libcoretest/num/uint_macros.rs | 1 + src/librand/chacha.rs | 1 + src/librand/distributions/mod.rs | 1 + src/librand/distributions/range.rs | 2 + src/librbml/lib.rs | 5 +- src/librustc/back/lto.rs | 1 + src/librustc/middle/check_match.rs | 1 + src/librustc/middle/trans/type_of.rs | 1 + src/librustc_back/sha2.rs | 2 + src/libserialize/json.rs | 3 +- src/libstd/fmt.rs | 1 + src/libstd/num/f32.rs | 1 + src/libstd/num/f64.rs | 1 + src/libstd/num/mod.rs | 9 +++- src/libstd/prelude.rs | 4 +- src/libstd/rand/reader.rs | 1 + src/libstd/sys/common/mod.rs | 1 + src/libstd/sys/common/net.rs | 1 + src/libstd/sys/unix/mod.rs | 1 + src/libsyntax/ast.rs | 1 + src/libsyntax/parse/mod.rs | 1 + src/libsyntax/parse/parser.rs | 1 + src/libtest/lib.rs | 1 + src/libtest/stats.rs | 9 ++-- src/test/bench/noise.rs | 1 + src/test/bench/shootout-fasta.rs | 1 + src/test/bench/shootout-k-nucleotide-pipes.rs | 1 + src/test/bench/shootout-nbody.rs | 2 + src/test/bench/shootout-spectralnorm.rs | 1 + src/test/bench/sudoku.rs | 1 + src/test/run-pass/generic-extern-mangle.rs | 2 + src/test/run-pass/issue-11736.rs | 1 + src/test/run-pass/trait-inheritance-num2.rs | 1 + src/test/run-pass/trait-inheritance-num3.rs | 4 +- 48 files changed, 100 insertions(+), 66 deletions(-) diff --git a/src/doc/guide-lifetimes.md b/src/doc/guide-lifetimes.md index b6ea1ddb3949..e3c050f0e901 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 4eaca64560ca..c2309ba479ea 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 1e9ab34b0aca..33d4406b733c 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 6ed9dad6252d..bfb5a010ed80 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 cc8581037649..ac8e45f9f941 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 43faaac39523..6082a0ca0137 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 9f51c6d1b5ea..4fad6081a934 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 fddb41c38ef2..5913b8d75a74 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 f06b7e97cf1c..8f68578d768b 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 6ec6839f0a0a..dd2ee6e01c62 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 045aca8aa0a8..7e35f20f0783 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 7e7e11a3645f..3bb8d735d9ca 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 { None } - fn to_u64(&self) -> Option { None } - } - - impl Add 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 { - None - } - } - - impl Clone for Foo { - fn clone(&self) -> Foo { - Foo - } - } - - impl Mul for Foo { - fn mul(&self, _: &Foo) -> Foo { - Foo - } - } - - impl num::One for Foo { - fn one() -> Foo { - Foo - } - } - assert!(range(0i, 5).collect::>() == vec![0i, 1, 2, 3, 4]); assert!(range(-10i, -1).collect::>() == 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 51af2e2916d9..a1b096bf4542 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 51a44ef4d596..38502321c1d2 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(ten: T, two: T) { +pub fn test_num(ten: T, two: T) where + T: PartialEq + NumCast + + Add + Sub + + Mul + Div + + Rem + 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 1d3f1718d72f..01a88119b647 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 97e68bcbb2c6..2693f1836443 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 26d5d3fb2f9e..73817a52fa78 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 e2762759e5ee..03270ff3c601 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 1dfc0d970a91..90cd7920e688 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 58db79f41ca4..3fbf830485b2 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 52bb0dc0784f..34b696a416d4 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 5e2df42d2d6e..a597325015c7 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 445279724b38..4319cd791b84 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 837784da6df3..626535f989ef 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 782ef098d81e..eb81935a8c90 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 c72b8205f19b..3f46cc8af50b 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 311fd0e87a32..4d691fc96769 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 28fe7538ca54..62e70e0c9dea 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(x: T, y: T) -> T { /// Helper function for testing numeric operations #[cfg(test)] -pub fn test_num(ten: T, two: T) { +pub fn test_num(ten: T, two: T) where + T: PartialEq + NumCast + + Add + Sub + + Mul + Div + + Rem + 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 3c20d205b774..0baae850eaa4 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 c8ed98052154..ab3216e93a09 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 65eb987afeaf..cacb128faa56 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 7c44142d93cd..7bb3c6b0ec95 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 939ae79facf7..969570d385c3 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 c21f34dcab07..bf5f7ff9ad32 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 0f364d1ba0b6..51738ece80f5 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 6873c015fd51..aab7c1b21784 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 ee6786414297..a25aff3eaffb 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 6be5bca552d1..5cec5076e068 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(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 19ccf1b6caf7..4ad77a695dd5 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 e61ed4745042..f9fafa977aca 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 b1cc52791ab8..e40c477ec66e 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 8486fa5b034d..3bcc0c25df8a 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 6bf594ce15d6..75f7a21ce0d7 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 54824d7259fa..6664eeecd5d8 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 69846750afc0..6e3d19b05d4b 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(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 cdd3252df4bd..912a62b5b0f6 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 aa35f2cd70f1..1e6e7227a067 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 415d0a04c8b9..bd93223093ad 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(n: T) { +fn num_eq_one(n: T) { println!("{}", n == NumCast::from(1i).unwrap()) }