Auto merge of #27871 - alexcrichton:stabilize-libcore, r=aturon

These commits move libcore into a state so that it's ready for stabilization, performing some minor cleanup:

* The primitive modules for integers in the standard library were all removed from the source tree as they were just straight reexports of the libcore variants.
* The `core::atomic` module now lives in `core::sync::atomic`. The `core::sync` module is otherwise empty, but ripe for expansion!
* The `core::prelude::v1` module was stabilized after auditing that it is a subset of the standard library's prelude plus some primitive extension traits (char, str, and slice)
* Some unstable-hacks for float parsing errors were shifted around to not use the same unstable hacks (e.g. the `flt2dec` module is now used for "privacy").


After this commit, the remaining large unstable functionality specific to libcore is:

* `raw`, `intrinsics`, `nonzero`, `array`, `panicking`, `simd` -- these modules are all unstable or not reexported in the standard library, so they're just remaining in the same status quo as before
* `num::Float` - this extension trait for floats needs to be audited for functionality (much of that is happening in #27823)  and may also want to be renamed to `FloatExt` or `F32Ext`/`F64Ext`.
* Should the extension traits for primitives be stabilized in libcore?

I believe other unstable pieces are not isolated to just libcore but also affect the standard library.

cc #27701
This commit is contained in:
bors 2015-08-22 09:59:07 +00:00
commit 94ee3b5a54
40 changed files with 242 additions and 459 deletions

View File

@ -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};

View File

@ -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;

View File

@ -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<f32, PFE> {
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<Self, ParseFloatError> {
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
}
/// Entry point for decimal-to-f64 conversion.
pub fn to_f64(s: &str) -> Result<f64, PFE> {
dec2flt(s)
#[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 }
}
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<T: RawFloat>(s: &str) -> Result<T, PFE> {
fn dec2flt<T: RawFloat>(s: &str) -> Result<T, ParseFloatError> {
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<T: RawFloat>(s: &str) -> Result<T, PFE> {
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<T: RawFloat>(s: &str) -> Result<T, PFE> {
/// 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<T: RawFloat>(mut decimal: Decimal) -> Result<T, PFE> {
fn convert<T: RawFloat>(mut decimal: Decimal) -> Result<T, ParseFloatError> {
simplify(&mut decimal);
if let Some(x) = trivial_cases(&decimal) {
return Ok(x);
@ -172,7 +246,7 @@ fn convert<T: RawFloat>(mut decimal: Decimal) -> Result<T, PFE> {
// 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);

View File

@ -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::<usize>()),
Some(('+', src)) => (true, src.parse::<usize>()),
Some((_, _)) => (true, src.parse::<usize>()),
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

View File

@ -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")]

View File

@ -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")]

View File

@ -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")]

View File

@ -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")]

View File

@ -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")]

View File

@ -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<Self, ParseFloatError> {
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;

View File

@ -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")]

View File

@ -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")]

View File

@ -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")]

View File

@ -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")]

View File

@ -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")]

View File

@ -10,4 +10,6 @@
//! The libcore prelude
#![stable(feature = "core_prelude", since = "1.4.0")]
pub mod v1;

View File

@ -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;

View File

@ -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;

View File

@ -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_() {

View File

@ -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::<f32>().unwrap().is_nan());
assert!("NaN".parse::<f64>().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::<f64>());
}
#[bench]
fn bench_42(b: &mut test::Bencher) {
b.iter(|| to_f64("42"));
b.iter(|| "42".parse::<f64>());
}
#[bench]
fn bench_huge_int(b: &mut test::Bencher) {
// 2^128 - 1
b.iter(|| to_f64("170141183460469231731687303715884105727"));
b.iter(|| "170141183460469231731687303715884105727".parse::<f64>());
}
#[bench]
fn bench_short_decimal(b: &mut test::Bencher) {
b.iter(|| to_f64("1234.5678"));
b.iter(|| "1234.5678".parse::<f64>());
}
#[bench]
fn bench_pi_long(b: &mut test::Bencher) {
b.iter(|| to_f64("3.14159265358979323846264338327950288"));
b.iter(|| "3.14159265358979323846264338327950288".parse::<f64>());
}
#[bench]
fn bench_pi_short(b: &mut test::Bencher) {
b.iter(|| to_f64("3.141592653589793"))
b.iter(|| "3.141592653589793".parse::<f64>())
}
#[bench]
fn bench_1e150(b: &mut test::Bencher) {
b.iter(|| to_f64("1e150"));
b.iter(|| "1e150".parse::<f64>());
}
#[bench]
fn bench_long_decimal_and_exp(b: &mut test::Bencher) {
b.iter(|| to_f64("727501488517303786137132964064381141071e-123"));
b.iter(|| "727501488517303786137132964064381141071e-123".parse::<f64>());
}
#[bench]
fn bench_min_subnormal(b: &mut test::Bencher) {
b.iter(|| to_f64("5e-324"));
b.iter(|| "5e-324".parse::<f64>());
}
#[bench]
fn bench_min_normal(b: &mut test::Bencher) {
b.iter(|| to_f64("2.2250738585072014e-308"));
b.iter(|| "2.2250738585072014e-308".parse::<f64>());
}
#[bench]
fn bench_max(b: &mut test::Bencher) {
b.iter(|| to_f64("1.7976931348623157e308"));
b.iter(|| "1.7976931348623157e308".parse::<f64>());
}

View File

@ -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: FromStr>(t: &str) -> Option<T> {
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::<u32>("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>);
}
}
)}

View File

@ -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.
// 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;
pub use core::isize;
pub use core::i8;
pub use core::i16;
pub use core::i32;
pub use core::i64;
#[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;
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;

View File

@ -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!`

View File

@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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);
})
}

View File

@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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 }

View File

@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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 }

View File

@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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 }

View File

@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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 }

View File

@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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 }

View File

@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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 }

View File

@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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 }

View File

@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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 }

View File

@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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 }

View File

@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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::FromStr>(t: &str) -> Option<T> {
::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::<u32>("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>);
}
}
) }

View File

@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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 }

View File

@ -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};

View File

@ -17,6 +17,6 @@ mod foo {
fn assert_clone<T>() where T : Clone { }
fn main() {
assert_clone::<foo::core::atomic::AtomicBool>();
assert_clone::<foo::core::sync::atomic::AtomicBool>();
//~^ ERROR the trait `foo::core::clone::Clone` is not implemented for the type `foo::core::
}
}

View File

@ -15,6 +15,6 @@ extern crate core as bar;
fn assert_clone<T>() where T : Clone { }
fn main() {
assert_clone::<bar::atomic::AtomicBool>();
//~^ ERROR the trait `bar::clone::Clone` is not implemented for the type `bar::atomic::
}
assert_clone::<bar::sync::atomic::AtomicBool>();
//~^ ERROR the trait `bar::clone::Clone` is not implemented for the type `bar::sync::atomic::
}

View File

@ -19,6 +19,6 @@ extern crate core;
fn assert_clone<T>() where T : Clone { }
fn main() {
assert_clone::<foo::core::atomic::AtomicBool>();
//~^ ERROR the trait `core::clone::Clone` is not implemented for the type `core::atomic::
}
assert_clone::<foo::core::sync::atomic::AtomicBool>();
//~^ ERROR the trait `core::clone::Clone` is not implemented for the type `core::sync::atomic::
}