Skip to content

Commit

Permalink
std: Clean up primitive integer modules
Browse files Browse the repository at this point in the history
All of the modules in the standard library were just straight reexports of those
in libcore, so remove all the "macro modules" from the standard library and just
reexport what's in core directly.
  • Loading branch information
alexcrichton committed Aug 17, 2015
1 parent 47ea0cf commit 8cb4d86
Show file tree
Hide file tree
Showing 26 changed files with 86 additions and 314 deletions.
4 changes: 3 additions & 1 deletion src/libcore/num/i16.rs
Expand Up @@ -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")]

Expand Down
4 changes: 3 additions & 1 deletion src/libcore/num/i32.rs
Expand Up @@ -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")]

Expand Down
4 changes: 3 additions & 1 deletion src/libcore/num/i64.rs
Expand Up @@ -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")]

Expand Down
4 changes: 3 additions & 1 deletion src/libcore/num/i8.rs
Expand Up @@ -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")]

Expand Down
4 changes: 3 additions & 1 deletion src/libcore/num/isize.rs
Expand Up @@ -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")]

Expand Down
4 changes: 3 additions & 1 deletion src/libcore/num/u16.rs
Expand Up @@ -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")]

Expand Down
4 changes: 3 additions & 1 deletion src/libcore/num/u32.rs
Expand Up @@ -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")]

Expand Down
4 changes: 3 additions & 1 deletion src/libcore/num/u64.rs
Expand Up @@ -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")]

Expand Down
4 changes: 3 additions & 1 deletion src/libcore/num/u8.rs
Expand Up @@ -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")]

Expand Down
4 changes: 3 additions & 1 deletion src/libcore/num/usize.rs
Expand Up @@ -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")]

Expand Down
32 changes: 31 additions & 1 deletion src/libcoretest/num/uint_macros.rs
Expand Up @@ -14,6 +14,7 @@ mod tests {
use core::$T_i::*;
use num;
use core::ops::{BitOr, BitAnd, BitXor, Shl, Shr, Not};
use std::str;

#[test]
fn test_overflows() {
Expand Down Expand Up @@ -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>);
}

)}
45 changes: 16 additions & 29 deletions src/libstd/lib.rs
Expand Up @@ -253,7 +253,6 @@
// Don't link to std. We are std.
#![no_std]

#![allow(trivial_casts)]
#![deny(missing_docs)]

#[cfg(test)] extern crate test;
Expand All @@ -263,7 +262,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]
Expand Down Expand Up @@ -307,7 +306,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;
Expand All @@ -326,32 +324,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;
Expand Down
9 changes: 9 additions & 0 deletions src/libstd/macros.rs
Expand Up @@ -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!`
Expand Down
19 changes: 0 additions & 19 deletions src/libstd/num/float_macros.rs

This file was deleted.

19 changes: 0 additions & 19 deletions src/libstd/num/i16.rs

This file was deleted.

19 changes: 0 additions & 19 deletions src/libstd/num/i32.rs

This file was deleted.

19 changes: 0 additions & 19 deletions src/libstd/num/i64.rs

This file was deleted.

19 changes: 0 additions & 19 deletions src/libstd/num/i8.rs

This file was deleted.

15 changes: 0 additions & 15 deletions src/libstd/num/int_macros.rs

This file was deleted.

19 changes: 0 additions & 19 deletions src/libstd/num/isize.rs

This file was deleted.

19 changes: 0 additions & 19 deletions src/libstd/num/u16.rs

This file was deleted.

0 comments on commit 8cb4d86

Please sign in to comment.