diff --git a/src/liballoc/arc.rs b/src/liballoc/arc.rs index aa71b7b132a12..bb2daa2a1d742 100644 --- a/src/liballoc/arc.rs +++ b/src/liballoc/arc.rs @@ -71,8 +71,8 @@ use boxed::Box; -use core::atomic; -use core::atomic::Ordering::{Relaxed, Release, Acquire, SeqCst}; +use core::sync::atomic; +use core::sync::atomic::Ordering::{Relaxed, Release, Acquire, SeqCst}; use core::fmt; use core::cmp::Ordering; use core::mem::{align_of_val, size_of_val}; diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index f05ef0fe5da55..551ea233f7627 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -144,7 +144,7 @@ pub mod convert; pub mod any; pub mod array; -pub mod atomic; +pub mod sync; pub mod cell; pub mod char; pub mod panicking; diff --git a/src/libcore/num/dec2flt/mod.rs b/src/libcore/num/dec2flt/mod.rs index 7c3c384ea93b7..4e6b6f04e9e92 100644 --- a/src/libcore/num/dec2flt/mod.rs +++ b/src/libcore/num/dec2flt/mod.rs @@ -96,8 +96,9 @@ issue = "0")] use prelude::v1::*; -use num::ParseFloatError as PFE; -use num::FloatErrorKind; +use fmt; +use str::FromStr; + use self::parse::{parse_decimal, Decimal, Sign}; use self::parse::ParseResult::{self, Valid, ShortcutToInf, ShortcutToZero}; use self::num::digits_to_big; @@ -110,14 +111,87 @@ mod num; pub mod rawfp; pub mod parse; -/// Entry point for decimal-to-f32 conversion. -pub fn to_f32(s: &str) -> Result { - dec2flt(s) +macro_rules! from_str_float_impl { + ($t:ty, $func:ident) => { + #[stable(feature = "rust1", since = "1.0.0")] + impl FromStr for $t { + type Err = ParseFloatError; + + /// Converts a string in base 10 to a float. + /// Accepts an optional decimal exponent. + /// + /// This function accepts strings such as + /// + /// * '3.14' + /// * '-3.14' + /// * '2.5E10', or equivalently, '2.5e10' + /// * '2.5E-10' + /// * '.' (understood as 0) + /// * '5.' + /// * '.5', or, equivalently, '0.5' + /// * 'inf', '-inf', 'NaN' + /// + /// Leading and trailing whitespace represent an error. + /// + /// # Arguments + /// + /// * src - A string + /// + /// # Return value + /// + /// `Err(ParseFloatError)` if the string did not represent a valid + /// number. Otherwise, `Ok(n)` where `n` is the floating-point + /// number represented by `src`. + #[inline] + fn from_str(src: &str) -> Result { + dec2flt(src) + } + } + } +} +from_str_float_impl!(f32, to_f32); +from_str_float_impl!(f64, to_f64); + +/// An error which can be returned when parsing a float. +#[derive(Debug, Clone, PartialEq)] +#[stable(feature = "rust1", since = "1.0.0")] +pub struct ParseFloatError { + kind: FloatErrorKind +} + +#[derive(Debug, Clone, PartialEq)] +enum FloatErrorKind { + Empty, + Invalid, +} + +impl ParseFloatError { + #[unstable(feature = "int_error_internals", + reason = "available through Error trait and this method should \ + not be exposed publicly", + issue = "0")] + #[doc(hidden)] + pub fn __description(&self) -> &str { + match self.kind { + FloatErrorKind::Empty => "cannot parse float from empty string", + FloatErrorKind::Invalid => "invalid float literal", + } + } +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl fmt::Display for ParseFloatError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.__description().fmt(f) + } +} + +pub fn pfe_empty() -> ParseFloatError { + ParseFloatError { kind: FloatErrorKind::Empty } } -/// Entry point for decimal-to-f64 conversion. -pub fn to_f64(s: &str) -> Result { - dec2flt(s) +pub fn pfe_invalid() -> ParseFloatError { + ParseFloatError { kind: FloatErrorKind::Invalid } } /// Split decimal string into sign and the rest, without inspecting or validating the rest. @@ -131,9 +205,9 @@ fn extract_sign(s: &str) -> (Sign, &str) { } /// Convert a decimal string into a floating point number. -fn dec2flt(s: &str) -> Result { +fn dec2flt(s: &str) -> Result { if s.is_empty() { - return Err(PFE { __kind: FloatErrorKind::Empty }); + return Err(pfe_empty()) } let (sign, s) = extract_sign(s); let flt = match parse_decimal(s) { @@ -143,7 +217,7 @@ fn dec2flt(s: &str) -> Result { ParseResult::Invalid => match s { "inf" => T::infinity(), "NaN" => T::nan(), - _ => { return Err(PFE { __kind: FloatErrorKind::Invalid }); } + _ => { return Err(pfe_invalid()); } } }; @@ -155,7 +229,7 @@ fn dec2flt(s: &str) -> Result { /// The main workhorse for the decimal-to-float conversion: Orchestrate all the preprocessing /// and figure out which algorithm should do the actual conversion. -fn convert(mut decimal: Decimal) -> Result { +fn convert(mut decimal: Decimal) -> Result { simplify(&mut decimal); if let Some(x) = trivial_cases(&decimal) { return Ok(x); @@ -172,7 +246,7 @@ fn convert(mut decimal: Decimal) -> Result { // If we exceed this, perhaps while calculating `f * 10^e` in Algorithm R or Algorithm M, // we'll crash. So we error out before getting too close, with a generous safety margin. if max_digits > 375 { - return Err(PFE { __kind: FloatErrorKind::Invalid }); + return Err(pfe_invalid()); } let f = digits_to_big(decimal.integral, decimal.fractional); diff --git a/src/libcore/num/float_macros.rs b/src/libcore/num/float_macros.rs index e3fa7047ec88c..88c3b756793a2 100644 --- a/src/libcore/num/float_macros.rs +++ b/src/libcore/num/float_macros.rs @@ -23,8 +23,7 @@ macro_rules! from_str_radix_float_impl { ($T:ty) => { fn from_str_radix(src: &str, radix: u32) -> Result<$T, ParseFloatError> { - use num::FloatErrorKind::*; - use num::ParseFloatError as PFE; + use num::dec2flt::{pfe_empty, pfe_invalid}; // Special values match src { @@ -35,8 +34,8 @@ macro_rules! from_str_radix_float_impl { } let (is_positive, src) = match src.slice_shift_char() { - None => return Err(PFE { __kind: Empty }), - Some(('-', "")) => return Err(PFE { __kind: Empty }), + None => return Err(pfe_empty()), + Some(('-', "")) => return Err(pfe_empty()), Some(('-', src)) => (false, src), Some((_, _)) => (true, src), }; @@ -88,7 +87,7 @@ macro_rules! from_str_radix_float_impl { break; // start of fractional part }, _ => { - return Err(PFE { __kind: Invalid }); + return Err(pfe_invalid()) }, }, } @@ -122,7 +121,7 @@ macro_rules! from_str_radix_float_impl { break; // start of exponent }, _ => { - return Err(PFE { __kind: Invalid }); + return Err(pfe_invalid()) }, }, } @@ -135,7 +134,7 @@ macro_rules! from_str_radix_float_impl { let base = match c { 'E' | 'e' if radix == 10 => 10.0, 'P' | 'p' if radix == 16 => 2.0, - _ => return Err(PFE { __kind: Invalid }), + _ => return Err(pfe_invalid()), }; // Parse the exponent as decimal integer @@ -144,13 +143,13 @@ macro_rules! from_str_radix_float_impl { Some(('-', src)) => (false, src.parse::()), Some(('+', src)) => (true, src.parse::()), Some((_, _)) => (true, src.parse::()), - None => return Err(PFE { __kind: Invalid }), + None => return Err(pfe_invalid()), }; match (is_positive, exp) { (true, Ok(exp)) => base.powi(exp as i32), (false, Ok(exp)) => 1.0 / base.powi(exp as i32), - (_, Err(_)) => return Err(PFE { __kind: Invalid }), + (_, Err(_)) => return Err(pfe_invalid()), } }, None => 1.0, // no exponent diff --git a/src/libcore/num/i16.rs b/src/libcore/num/i16.rs index dacb4ebcdfa3a..4054497941797 100644 --- a/src/libcore/num/i16.rs +++ b/src/libcore/num/i16.rs @@ -8,7 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -//! Operations and constants for signed 16-bits integers (`i16` type) +//! The 16-bit signed integer type. +//! +//! *[See also the `i16` primitive type](../primitive.i16.html).* #![stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libcore/num/i32.rs b/src/libcore/num/i32.rs index 250d66de70b34..5d2ade8d8e0e9 100644 --- a/src/libcore/num/i32.rs +++ b/src/libcore/num/i32.rs @@ -8,7 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -//! Operations and constants for signed 32-bits integers (`i32` type) +//! The 32-bit signed integer type. +//! +//! *[See also the `i32` primitive type](../primitive.i32.html).* #![stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libcore/num/i64.rs b/src/libcore/num/i64.rs index 5ed21d7246cd0..b1d43a3b83872 100644 --- a/src/libcore/num/i64.rs +++ b/src/libcore/num/i64.rs @@ -8,7 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -//! Operations and constants for signed 64-bits integers (`i64` type) +//! The 64-bit signed integer type. +//! +//! *[See also the `i64` primitive type](../primitive.i64.html).* #![stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libcore/num/i8.rs b/src/libcore/num/i8.rs index 0394c12d5c457..ee003d92b2823 100644 --- a/src/libcore/num/i8.rs +++ b/src/libcore/num/i8.rs @@ -8,7 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -//! Operations and constants for signed 8-bits integers (`i8` type) +//! The 8-bit signed integer type. +//! +//! *[See also the `i8` primitive type](../primitive.i8.html).* #![stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libcore/num/isize.rs b/src/libcore/num/isize.rs index 066cb10cce265..034a5c0eb89d4 100644 --- a/src/libcore/num/isize.rs +++ b/src/libcore/num/isize.rs @@ -8,7 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -//! Operations and constants for pointer-sized signed integers (`isize` type) +//! The pointer-sized signed integer type. +//! +//! *[See also the `isize` primitive type](../primitive.isize.html).* #![stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 23432a2044c45..05c7e8b8de48b 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -1327,47 +1327,6 @@ pub trait Float: Sized { fn to_radians(self) -> Self; } -macro_rules! from_str_float_impl { - ($t:ty, $func:ident) => { - #[stable(feature = "rust1", since = "1.0.0")] - impl FromStr for $t { - type Err = ParseFloatError; - - /// Converts a string in base 10 to a float. - /// Accepts an optional decimal exponent. - /// - /// This function accepts strings such as - /// - /// * '3.14' - /// * '-3.14' - /// * '2.5E10', or equivalently, '2.5e10' - /// * '2.5E-10' - /// * '.' (understood as 0) - /// * '5.' - /// * '.5', or, equivalently, '0.5' - /// * 'inf', '-inf', 'NaN' - /// - /// Leading and trailing whitespace represent an error. - /// - /// # Arguments - /// - /// * src - A string - /// - /// # Return value - /// - /// `Err(ParseFloatError)` if the string did not represent a valid - /// number. Otherwise, `Ok(n)` where `n` is the floating-point - /// number represented by `src`. - #[inline] - fn from_str(src: &str) -> Result { - dec2flt::$func(src) - } - } - } -} -from_str_float_impl!(f32, to_f32); -from_str_float_impl!(f64, to_f64); - macro_rules! from_str_radix_int_impl { ($($t:ty)*) => {$( #[stable(feature = "rust1", since = "1.0.0")] @@ -1510,40 +1469,4 @@ impl fmt::Display for ParseIntError { } } -/// An error which can be returned when parsing a float. -#[derive(Debug, Clone, PartialEq)] -#[stable(feature = "rust1", since = "1.0.0")] -pub struct ParseFloatError { - #[doc(hidden)] - #[unstable(feature = "float_error_internals", - reason = "should not be exposed publicly", - issue = "0")] - pub __kind: FloatErrorKind -} - -#[derive(Debug, Clone, PartialEq)] -#[unstable(feature = "float_error_internals", - reason = "should not be exposed publicly", - issue = "0")] -#[doc(hidden)] -pub enum FloatErrorKind { - Empty, - Invalid, -} - -impl ParseFloatError { - #[doc(hidden)] - pub fn __description(&self) -> &str { - match self.__kind { - FloatErrorKind::Empty => "cannot parse float from empty string", - FloatErrorKind::Invalid => "invalid float literal", - } - } -} - -#[stable(feature = "rust1", since = "1.0.0")] -impl fmt::Display for ParseFloatError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - self.__description().fmt(f) - } -} +pub use num::dec2flt::ParseFloatError; diff --git a/src/libcore/num/u16.rs b/src/libcore/num/u16.rs index ecf799448483c..68e50e8a400ea 100644 --- a/src/libcore/num/u16.rs +++ b/src/libcore/num/u16.rs @@ -8,7 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -//! Operations and constants for unsigned 16-bits integers (`u16` type) +//! The 16-bit unsigned integer type. +//! +//! *[See also the `u16` primitive type](../primitive.u16.html).* #![stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libcore/num/u32.rs b/src/libcore/num/u32.rs index b0682b55ac05d..c1ee96b363c27 100644 --- a/src/libcore/num/u32.rs +++ b/src/libcore/num/u32.rs @@ -8,7 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -//! Operations and constants for unsigned 32-bits integers (`u32` type) +//! The 32-bit unsigned integer type. +//! +//! *[See also the `u32` primitive type](../primitive.u32.html).* #![stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libcore/num/u64.rs b/src/libcore/num/u64.rs index dbc6a64a905d2..c0d18d850a796 100644 --- a/src/libcore/num/u64.rs +++ b/src/libcore/num/u64.rs @@ -8,7 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -//! Operations and constants for unsigned 64-bits integer (`u64` type) +//! The 64-bit unsigned integer type. +//! +//! *[See also the `u64` primitive type](../primitive.u64.html).* #![stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libcore/num/u8.rs b/src/libcore/num/u8.rs index bf9347ca62c92..a60c480d810ea 100644 --- a/src/libcore/num/u8.rs +++ b/src/libcore/num/u8.rs @@ -8,7 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -//! Operations and constants for unsigned 8-bits integers (`u8` type) +//! The 8-bit unsigned integer type. +//! +//! *[See also the `u8` primitive type](../primitive.u8.html).* #![stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libcore/num/usize.rs b/src/libcore/num/usize.rs index 67e3c954ab695..70e790106e1c6 100644 --- a/src/libcore/num/usize.rs +++ b/src/libcore/num/usize.rs @@ -8,7 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -//! Operations and constants for pointer-sized unsigned integers (`usize` type) +//! The pointer-sized unsigned integer type. +//! +//! *[See also the `usize` primitive type](../primitive.usize.html).* #![stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libcore/prelude/mod.rs b/src/libcore/prelude/mod.rs index b6c9361537813..99b1947c84e4f 100644 --- a/src/libcore/prelude/mod.rs +++ b/src/libcore/prelude/mod.rs @@ -10,4 +10,6 @@ //! The libcore prelude +#![stable(feature = "core_prelude", since = "1.4.0")] + pub mod v1; diff --git a/src/libcore/prelude/v1.rs b/src/libcore/prelude/v1.rs index fc4e4e668174a..0457188586e49 100644 --- a/src/libcore/prelude/v1.rs +++ b/src/libcore/prelude/v1.rs @@ -14,27 +14,26 @@ //! well. This module is imported by default when `#![no_std]` is used in the //! same manner as the standard library's prelude. -#![unstable(feature = "core_prelude", - reason = "the libcore prelude has not been scrutinized and \ - stabilized yet", - issue = "27701")] +#![stable(feature = "core_prelude", since = "1.4.0")] // Reexported core operators -pub use marker::{Copy, Send, Sized, Sync}; -pub use ops::{Drop, Fn, FnMut, FnOnce}; +#[doc(no_inline)] pub use marker::{Copy, Send, Sized, Sync}; +#[doc(no_inline)] pub use ops::{Drop, Fn, FnMut, FnOnce}; // Reexported functions -pub use mem::drop; +#[doc(no_inline)] pub use mem::drop; // Reexported types and traits -pub use char::CharExt; -pub use clone::Clone; -pub use cmp::{PartialEq, PartialOrd, Eq, Ord}; -pub use convert::{AsRef, AsMut, Into, From}; -pub use default::Default; -pub use iter::IntoIterator; -pub use iter::{Iterator, DoubleEndedIterator, Extend, ExactSizeIterator}; -pub use option::Option::{self, Some, None}; -pub use result::Result::{self, Ok, Err}; -pub use slice::SliceExt; -pub use str::StrExt; +#[doc(no_inline)] pub use clone::Clone; +#[doc(no_inline)] pub use cmp::{PartialEq, PartialOrd, Eq, Ord}; +#[doc(no_inline)] pub use convert::{AsRef, AsMut, Into, From}; +#[doc(no_inline)] pub use default::Default; +#[doc(no_inline)] pub use iter::{Iterator, Extend, IntoIterator}; +#[doc(no_inline)] pub use iter::{DoubleEndedIterator, ExactSizeIterator}; +#[doc(no_inline)] pub use option::Option::{self, Some, None}; +#[doc(no_inline)] pub use result::Result::{self, Ok, Err}; + +// Reexported extension traits for primitive types +#[doc(no_inline)] pub use slice::SliceExt; +#[doc(no_inline)] pub use str::StrExt; +#[doc(no_inline)] pub use char::CharExt; diff --git a/src/libcore/atomic.rs b/src/libcore/sync/atomic.rs similarity index 100% rename from src/libcore/atomic.rs rename to src/libcore/sync/atomic.rs diff --git a/src/libstd/num/int_macros.rs b/src/libcore/sync/mod.rs similarity index 71% rename from src/libstd/num/int_macros.rs rename to src/libcore/sync/mod.rs index 178fad09f9881..0080e0b5e4353 100644 --- a/src/libstd/num/int_macros.rs +++ b/src/libcore/sync/mod.rs @@ -1,4 +1,4 @@ -// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -8,8 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![doc(hidden)] +//! Synchronization primitives -macro_rules! int_module { ($T:ty) => ( +#![stable(feature = "rust1", since = "1.0.0")] -) } +pub mod atomic; diff --git a/src/libcoretest/atomic.rs b/src/libcoretest/atomic.rs index c50f18c235233..b6bb5fddf4a4b 100644 --- a/src/libcoretest/atomic.rs +++ b/src/libcoretest/atomic.rs @@ -8,8 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use core::atomic::*; -use core::atomic::Ordering::SeqCst; +use core::sync::atomic::*; +use core::sync::atomic::Ordering::SeqCst; #[test] fn bool_() { diff --git a/src/libcoretest/num/dec2flt/mod.rs b/src/libcoretest/num/dec2flt/mod.rs index b7ef956055e29..131cf62957537 100644 --- a/src/libcoretest/num/dec2flt/mod.rs +++ b/src/libcoretest/num/dec2flt/mod.rs @@ -12,7 +12,6 @@ use std::{i64, f32, f64}; use test; -use core::num::dec2flt::{to_f32, to_f64}; mod parse; mod rawfp; @@ -27,11 +26,11 @@ macro_rules! test_literal { let inputs = &[stringify!($x).into(), format!("{:?}", x64), format!("{:e}", x64)]; for input in inputs { if input != "inf" { - assert_eq!(to_f64(input), Ok(x64)); - assert_eq!(to_f32(input), Ok(x32)); + assert_eq!(input.parse(), Ok(x64)); + assert_eq!(input.parse(), Ok(x32)); let neg_input = &format!("-{}", input); - assert_eq!(to_f64(neg_input), Ok(-x64)); - assert_eq!(to_f32(neg_input), Ok(-x32)); + assert_eq!(neg_input.parse(), Ok(-x64)); + assert_eq!(neg_input.parse(), Ok(-x32)); } } }) @@ -99,83 +98,83 @@ fn fast_path_correct() { #[test] fn lonely_dot() { - assert_eq!(to_f64("."), Ok(0.0)); + assert_eq!(".".parse(), Ok(0.0)); } #[test] fn nan() { - assert!(to_f64("NaN").unwrap().is_nan()); - assert!(to_f32("NaN").unwrap().is_nan()); + assert!("NaN".parse::().unwrap().is_nan()); + assert!("NaN".parse::().unwrap().is_nan()); } #[test] fn inf() { - assert_eq!(to_f64("inf"), Ok(f64::INFINITY)); - assert_eq!(to_f64("-inf"), Ok(f64::NEG_INFINITY)); - assert_eq!(to_f32("inf"), Ok(f32::INFINITY)); - assert_eq!(to_f32("-inf"), Ok(f32::NEG_INFINITY)); + assert_eq!("inf".parse(), Ok(f64::INFINITY)); + assert_eq!("-inf".parse(), Ok(f64::NEG_INFINITY)); + assert_eq!("inf".parse(), Ok(f32::INFINITY)); + assert_eq!("-inf".parse(), Ok(f32::NEG_INFINITY)); } #[test] fn massive_exponent() { let max = i64::MAX; - assert_eq!(to_f64(&format!("1e{}000", max)), Ok(f64::INFINITY)); - assert_eq!(to_f64(&format!("1e-{}000", max)), Ok(0.0)); - assert_eq!(to_f64(&format!("1e{}000", max)), Ok(f64::INFINITY)); + assert_eq!(format!("1e{}000", max).parse(), Ok(f64::INFINITY)); + assert_eq!(format!("1e-{}000", max).parse(), Ok(0.0)); + assert_eq!(format!("1e{}000", max).parse(), Ok(f64::INFINITY)); } #[bench] fn bench_0(b: &mut test::Bencher) { - b.iter(|| to_f64("0.0")); + b.iter(|| "0.0".parse::()); } #[bench] fn bench_42(b: &mut test::Bencher) { - b.iter(|| to_f64("42")); + b.iter(|| "42".parse::()); } #[bench] fn bench_huge_int(b: &mut test::Bencher) { // 2^128 - 1 - b.iter(|| to_f64("170141183460469231731687303715884105727")); + b.iter(|| "170141183460469231731687303715884105727".parse::()); } #[bench] fn bench_short_decimal(b: &mut test::Bencher) { - b.iter(|| to_f64("1234.5678")); + b.iter(|| "1234.5678".parse::()); } #[bench] fn bench_pi_long(b: &mut test::Bencher) { - b.iter(|| to_f64("3.14159265358979323846264338327950288")); + b.iter(|| "3.14159265358979323846264338327950288".parse::()); } #[bench] fn bench_pi_short(b: &mut test::Bencher) { - b.iter(|| to_f64("3.141592653589793")) + b.iter(|| "3.141592653589793".parse::()) } #[bench] fn bench_1e150(b: &mut test::Bencher) { - b.iter(|| to_f64("1e150")); + b.iter(|| "1e150".parse::()); } #[bench] fn bench_long_decimal_and_exp(b: &mut test::Bencher) { - b.iter(|| to_f64("727501488517303786137132964064381141071e-123")); + b.iter(|| "727501488517303786137132964064381141071e-123".parse::()); } #[bench] fn bench_min_subnormal(b: &mut test::Bencher) { - b.iter(|| to_f64("5e-324")); + b.iter(|| "5e-324".parse::()); } #[bench] fn bench_min_normal(b: &mut test::Bencher) { - b.iter(|| to_f64("2.2250738585072014e-308")); + b.iter(|| "2.2250738585072014e-308".parse::()); } #[bench] fn bench_max(b: &mut test::Bencher) { - b.iter(|| to_f64("1.7976931348623157e308")); + b.iter(|| "1.7976931348623157e308".parse::()); } diff --git a/src/libcoretest/num/uint_macros.rs b/src/libcoretest/num/uint_macros.rs index 1712345f9d9a7..25591db64d907 100644 --- a/src/libcoretest/num/uint_macros.rs +++ b/src/libcoretest/num/uint_macros.rs @@ -14,6 +14,7 @@ mod tests { use core::$T_i::*; use num; use core::ops::{BitOr, BitAnd, BitXor, Shl, Shr, Not}; + use std::str::FromStr; #[test] fn test_overflows() { @@ -121,6 +122,35 @@ mod tests { assert!((10 as $T).checked_div(2) == Some(5)); assert!((5 as $T).checked_div(0) == None); } -} + fn from_str(t: &str) -> Option { + FromStr::from_str(t).ok() + } + + #[test] + pub fn test_from_str() { + assert_eq!(from_str::<$T>("0"), Some(0 as $T)); + assert_eq!(from_str::<$T>("3"), Some(3 as $T)); + assert_eq!(from_str::<$T>("10"), Some(10 as $T)); + assert_eq!(from_str::("123456789"), Some(123456789 as u32)); + assert_eq!(from_str::<$T>("00100"), Some(100 as $T)); + + assert_eq!(from_str::<$T>(""), None); + assert_eq!(from_str::<$T>(" "), None); + assert_eq!(from_str::<$T>("x"), None); + } + + #[test] + pub fn test_parse_bytes() { + assert_eq!($T::from_str_radix("123", 10), Ok(123 as $T)); + assert_eq!($T::from_str_radix("1001", 2), Ok(9 as $T)); + assert_eq!($T::from_str_radix("123", 8), Ok(83 as $T)); + assert_eq!(u16::from_str_radix("123", 16), Ok(291 as u16)); + assert_eq!(u16::from_str_radix("ffff", 16), Ok(65535 as u16)); + assert_eq!($T::from_str_radix("z", 36), Ok(35 as $T)); + + assert_eq!($T::from_str_radix("Z", 10).ok(), None::<$T>); + assert_eq!($T::from_str_radix("_", 2).ok(), None::<$T>); + } +} )} diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index baca87809a66b..179f0727d46f3 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -254,7 +254,6 @@ // Don't link to std. We are std. #![no_std] -#![allow(trivial_casts)] #![deny(missing_docs)] #[cfg(test)] extern crate test; @@ -264,7 +263,7 @@ // imported by the compiler (via our #[no_std] attribute) In this case we just // add a new crate name so we can attach the reexports to it. #[macro_reexport(assert, assert_eq, debug_assert, debug_assert_eq, - unreachable, unimplemented, write, writeln)] + unreachable, unimplemented, write, writeln)] extern crate core as __core; #[macro_use] @@ -309,7 +308,6 @@ pub use core_collections::fmt; pub use core_collections::slice; pub use core_collections::str; pub use core_collections::string; -#[stable(feature = "rust1", since = "1.0.0")] pub use core_collections::vec; pub use rustc_unicode::char; @@ -328,32 +326,21 @@ pub mod prelude; /* Primitive types */ -// NB: slice and str are primitive types too, but their module docs + primitive doc pages -// are inlined from the public re-exports of core_collections::{slice, str} above. - -#[path = "num/float_macros.rs"] -#[macro_use] -mod float_macros; - -#[path = "num/int_macros.rs"] -#[macro_use] -mod int_macros; - -#[path = "num/uint_macros.rs"] -#[macro_use] -mod uint_macros; - -#[path = "num/isize.rs"] pub mod isize; -#[path = "num/i8.rs"] pub mod i8; -#[path = "num/i16.rs"] pub mod i16; -#[path = "num/i32.rs"] pub mod i32; -#[path = "num/i64.rs"] pub mod i64; - -#[path = "num/usize.rs"] pub mod usize; -#[path = "num/u8.rs"] pub mod u8; -#[path = "num/u16.rs"] pub mod u16; -#[path = "num/u32.rs"] pub mod u32; -#[path = "num/u64.rs"] pub mod u64; +// NB: slice and str are primitive types too, but their module docs + primitive +// doc pages are inlined from the public re-exports of core_collections::{slice, +// str} above. + +pub use core::isize; +pub use core::i8; +pub use core::i16; +pub use core::i32; +pub use core::i64; + +pub use core::usize; +pub use core::u8; +pub use core::u16; +pub use core::u32; +pub use core::u64; #[path = "num/f32.rs"] pub mod f32; #[path = "num/f64.rs"] pub mod f64; diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index eb378bf408028..53a14c2b21b17 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -197,6 +197,15 @@ macro_rules! log { ) } +#[cfg(test)] +macro_rules! assert_approx_eq { + ($a:expr, $b:expr) => ({ + let (a, b) = (&$a, &$b); + assert!((*a - *b).abs() < 1.0e-6, + "{} is not approximately equal to {}", *a, *b); + }) +} + /// Built-in macros to the compiler itself. /// /// These macros do not have any corresponding definition with a `macro_rules!` diff --git a/src/libstd/num/float_macros.rs b/src/libstd/num/float_macros.rs deleted file mode 100644 index 16ad21a07d700..0000000000000 --- a/src/libstd/num/float_macros.rs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![doc(hidden)] - -macro_rules! assert_approx_eq { - ($a:expr, $b:expr) => ({ - let (a, b) = (&$a, &$b); - assert!((*a - *b).abs() < 1.0e-6, - "{} is not approximately equal to {}", *a, *b); - }) -} diff --git a/src/libstd/num/i16.rs b/src/libstd/num/i16.rs deleted file mode 100644 index eb53e0821f2a6..0000000000000 --- a/src/libstd/num/i16.rs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! The 16-bit signed integer type. -//! -//! *[See also the `i16` primitive type](../primitive.i16.html).* - -#![stable(feature = "rust1", since = "1.0.0")] - -pub use core::i16::{BITS, BYTES, MIN, MAX}; - -int_module! { i16 } diff --git a/src/libstd/num/i32.rs b/src/libstd/num/i32.rs deleted file mode 100644 index 3c9eedf38c7cd..0000000000000 --- a/src/libstd/num/i32.rs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! The 32-bit signed integer type. -//! -//! *[See also the `i32` primitive type](../primitive.i32.html).* - -#![stable(feature = "rust1", since = "1.0.0")] - -pub use core::i32::{BITS, BYTES, MIN, MAX}; - -int_module! { i32 } diff --git a/src/libstd/num/i64.rs b/src/libstd/num/i64.rs deleted file mode 100644 index 2df7478a820bf..0000000000000 --- a/src/libstd/num/i64.rs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! The 64-bit signed integer type. -//! -//! *[See also the `i64` primitive type](../primitive.i64.html).* - -#![stable(feature = "rust1", since = "1.0.0")] - -pub use core::i64::{BITS, BYTES, MIN, MAX}; - -int_module! { i64 } diff --git a/src/libstd/num/i8.rs b/src/libstd/num/i8.rs deleted file mode 100644 index 4e4bee8a791e4..0000000000000 --- a/src/libstd/num/i8.rs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! The 8-bit signed integer type. -//! -//! *[See also the `i8` primitive type](../primitive.i8.html).* - -#![stable(feature = "rust1", since = "1.0.0")] - -pub use core::i8::{BITS, BYTES, MIN, MAX}; - -int_module! { i8 } diff --git a/src/libstd/num/isize.rs b/src/libstd/num/isize.rs deleted file mode 100644 index d46b6b80d0d25..0000000000000 --- a/src/libstd/num/isize.rs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! The pointer-sized signed integer type. -//! -//! *[See also the `isize` primitive type](../primitive.isize.html).* - -#![stable(feature = "rust1", since = "1.0.0")] - -pub use core::isize::{BITS, BYTES, MIN, MAX}; - -int_module! { isize } diff --git a/src/libstd/num/u16.rs b/src/libstd/num/u16.rs deleted file mode 100644 index 893618aeffafd..0000000000000 --- a/src/libstd/num/u16.rs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! The 16-bit unsigned integer type. -//! -//! *[See also the `u16` primitive type](../primitive.u16.html).* - -#![stable(feature = "rust1", since = "1.0.0")] - -pub use core::u16::{BITS, BYTES, MIN, MAX}; - -uint_module! { u16 } diff --git a/src/libstd/num/u32.rs b/src/libstd/num/u32.rs deleted file mode 100644 index 2da2551969657..0000000000000 --- a/src/libstd/num/u32.rs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! The 32-bit unsigned integer type. -//! -//! *[See also the `u32` primitive type](../primitive.u32.html).* - -#![stable(feature = "rust1", since = "1.0.0")] - -pub use core::u32::{BITS, BYTES, MIN, MAX}; - -uint_module! { u32 } diff --git a/src/libstd/num/u64.rs b/src/libstd/num/u64.rs deleted file mode 100644 index 26a8b53739403..0000000000000 --- a/src/libstd/num/u64.rs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! The 64-bit unsigned integer type. -//! -//! *[See also the `u64` primitive type](../primitive.u64.html).* - -#![stable(feature = "rust1", since = "1.0.0")] - -pub use core::u64::{BITS, BYTES, MIN, MAX}; - -uint_module! { u64 } diff --git a/src/libstd/num/u8.rs b/src/libstd/num/u8.rs deleted file mode 100644 index 385754b93a04b..0000000000000 --- a/src/libstd/num/u8.rs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! The 8-bit unsigned integer type. -//! -//! *[See also the `u8` primitive type](../primitive.u8.html).* - -#![stable(feature = "rust1", since = "1.0.0")] - -pub use core::u8::{BITS, BYTES, MIN, MAX}; - -uint_module! { u8 } diff --git a/src/libstd/num/uint_macros.rs b/src/libstd/num/uint_macros.rs deleted file mode 100644 index 902c78c0a46f8..0000000000000 --- a/src/libstd/num/uint_macros.rs +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![doc(hidden)] - -macro_rules! uint_module { ($T:ident) => ( - -#[cfg(test)] -mod tests { - use prelude::v1::*; - - fn from_str(t: &str) -> Option { - ::str::FromStr::from_str(t).ok() - } - - #[test] - pub fn test_from_str() { - assert_eq!(from_str::<$T>("0"), Some(0 as $T)); - assert_eq!(from_str::<$T>("3"), Some(3 as $T)); - assert_eq!(from_str::<$T>("10"), Some(10 as $T)); - assert_eq!(from_str::("123456789"), Some(123456789 as u32)); - assert_eq!(from_str::<$T>("00100"), Some(100 as $T)); - - assert_eq!(from_str::<$T>(""), None); - assert_eq!(from_str::<$T>(" "), None); - assert_eq!(from_str::<$T>("x"), None); - } - - #[test] - pub fn test_parse_bytes() { - assert_eq!($T::from_str_radix("123", 10), Ok(123 as $T)); - assert_eq!($T::from_str_radix("1001", 2), Ok(9 as $T)); - assert_eq!($T::from_str_radix("123", 8), Ok(83 as $T)); - assert_eq!(u16::from_str_radix("123", 16), Ok(291 as u16)); - assert_eq!(u16::from_str_radix("ffff", 16), Ok(65535 as u16)); - assert_eq!($T::from_str_radix("z", 36), Ok(35 as $T)); - - assert_eq!($T::from_str_radix("Z", 10).ok(), None::<$T>); - assert_eq!($T::from_str_radix("_", 2).ok(), None::<$T>); - } -} - -) } diff --git a/src/libstd/num/usize.rs b/src/libstd/num/usize.rs deleted file mode 100644 index 6960ba3b8296b..0000000000000 --- a/src/libstd/num/usize.rs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! The pointer-sized unsigned integer type. -//! -//! *[See also the `usize` primitive type](../primitive.usize.html).* - -#![stable(feature = "rust1", since = "1.0.0")] - -pub use core::usize::{BITS, BYTES, MIN, MAX}; - -uint_module! { usize } diff --git a/src/libstd/sync/mod.rs b/src/libstd/sync/mod.rs index ae21503cf6746..4544f30d4f497 100644 --- a/src/libstd/sync/mod.rs +++ b/src/libstd/sync/mod.rs @@ -18,7 +18,7 @@ #![stable(feature = "rust1", since = "1.0.0")] pub use alloc::arc::{Arc, Weak}; -pub use core::atomic; +pub use core::sync::atomic; pub use self::barrier::{Barrier, BarrierWaitResult}; pub use self::condvar::{Condvar, StaticCondvar, WaitTimeoutResult, CONDVAR_INIT}; diff --git a/src/test/compile-fail/issue-1920-1.rs b/src/test/compile-fail/issue-1920-1.rs index c26c5ff8421d9..8c75d4680faeb 100644 --- a/src/test/compile-fail/issue-1920-1.rs +++ b/src/test/compile-fail/issue-1920-1.rs @@ -17,6 +17,6 @@ mod foo { fn assert_clone() where T : Clone { } fn main() { - assert_clone::(); + assert_clone::(); //~^ ERROR the trait `foo::core::clone::Clone` is not implemented for the type `foo::core:: -} \ No newline at end of file +} diff --git a/src/test/compile-fail/issue-1920-2.rs b/src/test/compile-fail/issue-1920-2.rs index 63cfcbdd8c700..57eb82a156bbf 100644 --- a/src/test/compile-fail/issue-1920-2.rs +++ b/src/test/compile-fail/issue-1920-2.rs @@ -15,6 +15,6 @@ extern crate core as bar; fn assert_clone() where T : Clone { } fn main() { - assert_clone::(); - //~^ ERROR the trait `bar::clone::Clone` is not implemented for the type `bar::atomic:: -} \ No newline at end of file + assert_clone::(); + //~^ ERROR the trait `bar::clone::Clone` is not implemented for the type `bar::sync::atomic:: +} diff --git a/src/test/compile-fail/issue-1920-3.rs b/src/test/compile-fail/issue-1920-3.rs index 619c8c3f3a4f0..0ef7747c8a84f 100644 --- a/src/test/compile-fail/issue-1920-3.rs +++ b/src/test/compile-fail/issue-1920-3.rs @@ -19,6 +19,6 @@ extern crate core; fn assert_clone() where T : Clone { } fn main() { - assert_clone::(); - //~^ ERROR the trait `core::clone::Clone` is not implemented for the type `core::atomic:: -} \ No newline at end of file + assert_clone::(); + //~^ ERROR the trait `core::clone::Clone` is not implemented for the type `core::sync::atomic:: +}