Skip to content

Commit 8cb4d86

Browse files
committed
std: Clean up primitive integer modules
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.
1 parent 47ea0cf commit 8cb4d86

26 files changed

+86
-314
lines changed

src/libcore/num/i16.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
//! Operations and constants for signed 16-bits integers (`i16` type)
11+
//! The 16-bit signed integer type.
12+
//!
13+
//! *[See also the `i16` primitive type](../primitive.i16.html).*
1214
1315
#![stable(feature = "rust1", since = "1.0.0")]
1416

src/libcore/num/i32.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
//! Operations and constants for signed 32-bits integers (`i32` type)
11+
//! The 32-bit signed integer type.
12+
//!
13+
//! *[See also the `i32` primitive type](../primitive.i32.html).*
1214
1315
#![stable(feature = "rust1", since = "1.0.0")]
1416

src/libcore/num/i64.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
//! Operations and constants for signed 64-bits integers (`i64` type)
11+
//! The 64-bit signed integer type.
12+
//!
13+
//! *[See also the `i64` primitive type](../primitive.i64.html).*
1214
1315
#![stable(feature = "rust1", since = "1.0.0")]
1416

src/libcore/num/i8.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
//! Operations and constants for signed 8-bits integers (`i8` type)
11+
//! The 8-bit signed integer type.
12+
//!
13+
//! *[See also the `i8` primitive type](../primitive.i8.html).*
1214
1315
#![stable(feature = "rust1", since = "1.0.0")]
1416

src/libcore/num/isize.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
//! Operations and constants for pointer-sized signed integers (`isize` type)
11+
//! The pointer-sized signed integer type.
12+
//!
13+
//! *[See also the `isize` primitive type](../primitive.isize.html).*
1214
1315
#![stable(feature = "rust1", since = "1.0.0")]
1416

src/libcore/num/u16.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
//! Operations and constants for unsigned 16-bits integers (`u16` type)
11+
//! The 16-bit unsigned integer type.
12+
//!
13+
//! *[See also the `u16` primitive type](../primitive.u16.html).*
1214
1315
#![stable(feature = "rust1", since = "1.0.0")]
1416

src/libcore/num/u32.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
//! Operations and constants for unsigned 32-bits integers (`u32` type)
11+
//! The 32-bit unsigned integer type.
12+
//!
13+
//! *[See also the `u32` primitive type](../primitive.u32.html).*
1214
1315
#![stable(feature = "rust1", since = "1.0.0")]
1416

src/libcore/num/u64.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
//! Operations and constants for unsigned 64-bits integer (`u64` type)
11+
//! The 64-bit unsigned integer type.
12+
//!
13+
//! *[See also the `u64` primitive type](../primitive.u64.html).*
1214
1315
#![stable(feature = "rust1", since = "1.0.0")]
1416

src/libcore/num/u8.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
//! Operations and constants for unsigned 8-bits integers (`u8` type)
11+
//! The 8-bit unsigned integer type.
12+
//!
13+
//! *[See also the `u8` primitive type](../primitive.u8.html).*
1214
1315
#![stable(feature = "rust1", since = "1.0.0")]
1416

src/libcore/num/usize.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
//! Operations and constants for pointer-sized unsigned integers (`usize` type)
11+
//! The pointer-sized unsigned integer type.
12+
//!
13+
//! *[See also the `usize` primitive type](../primitive.usize.html).*
1214
1315
#![stable(feature = "rust1", since = "1.0.0")]
1416

src/libcoretest/num/uint_macros.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ mod tests {
1414
use core::$T_i::*;
1515
use num;
1616
use core::ops::{BitOr, BitAnd, BitXor, Shl, Shr, Not};
17+
use std::str;
1718

1819
#[test]
1920
fn test_overflows() {
@@ -121,6 +122,35 @@ mod tests {
121122
assert!((10 as $T).checked_div(2) == Some(5));
122123
assert!((5 as $T).checked_div(0) == None);
123124
}
124-
}
125+
126+
fn from_str<T: FromStr>(t: &str) -> Option<T> {
127+
FromStr::from_str(t).ok()
128+
}
129+
130+
#[test]
131+
pub fn test_from_str() {
132+
assert_eq!(from_str::<$T>("0"), Some(0 as $T));
133+
assert_eq!(from_str::<$T>("3"), Some(3 as $T));
134+
assert_eq!(from_str::<$T>("10"), Some(10 as $T));
135+
assert_eq!(from_str::<u32>("123456789"), Some(123456789 as u32));
136+
assert_eq!(from_str::<$T>("00100"), Some(100 as $T));
137+
138+
assert_eq!(from_str::<$T>(""), None);
139+
assert_eq!(from_str::<$T>(" "), None);
140+
assert_eq!(from_str::<$T>("x"), None);
141+
}
142+
143+
#[test]
144+
pub fn test_parse_bytes() {
145+
assert_eq!($T::from_str_radix("123", 10), Ok(123 as $T));
146+
assert_eq!($T::from_str_radix("1001", 2), Ok(9 as $T));
147+
assert_eq!($T::from_str_radix("123", 8), Ok(83 as $T));
148+
assert_eq!(u16::from_str_radix("123", 16), Ok(291 as u16));
149+
assert_eq!(u16::from_str_radix("ffff", 16), Ok(65535 as u16));
150+
assert_eq!($T::from_str_radix("z", 36), Ok(35 as $T));
151+
152+
assert_eq!($T::from_str_radix("Z", 10).ok(), None::<$T>);
153+
assert_eq!($T::from_str_radix("_", 2).ok(), None::<$T>);
154+
}
125155

126156
)}

src/libstd/lib.rs

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,6 @@
253253
// Don't link to std. We are std.
254254
#![no_std]
255255

256-
#![allow(trivial_casts)]
257256
#![deny(missing_docs)]
258257

259258
#[cfg(test)] extern crate test;
@@ -263,7 +262,7 @@
263262
// imported by the compiler (via our #[no_std] attribute) In this case we just
264263
// add a new crate name so we can attach the reexports to it.
265264
#[macro_reexport(assert, assert_eq, debug_assert, debug_assert_eq,
266-
unreachable, unimplemented, write, writeln)]
265+
unreachable, unimplemented, write, writeln)]
267266
extern crate core as __core;
268267

269268
#[macro_use]
@@ -307,7 +306,6 @@ pub use core_collections::fmt;
307306
pub use core_collections::slice;
308307
pub use core_collections::str;
309308
pub use core_collections::string;
310-
#[stable(feature = "rust1", since = "1.0.0")]
311309
pub use core_collections::vec;
312310

313311
pub use rustc_unicode::char;
@@ -326,32 +324,21 @@ pub mod prelude;
326324

327325
/* Primitive types */
328326

329-
// NB: slice and str are primitive types too, but their module docs + primitive doc pages
330-
// are inlined from the public re-exports of core_collections::{slice, str} above.
331-
332-
#[path = "num/float_macros.rs"]
333-
#[macro_use]
334-
mod float_macros;
335-
336-
#[path = "num/int_macros.rs"]
337-
#[macro_use]
338-
mod int_macros;
339-
340-
#[path = "num/uint_macros.rs"]
341-
#[macro_use]
342-
mod uint_macros;
343-
344-
#[path = "num/isize.rs"] pub mod isize;
345-
#[path = "num/i8.rs"] pub mod i8;
346-
#[path = "num/i16.rs"] pub mod i16;
347-
#[path = "num/i32.rs"] pub mod i32;
348-
#[path = "num/i64.rs"] pub mod i64;
349-
350-
#[path = "num/usize.rs"] pub mod usize;
351-
#[path = "num/u8.rs"] pub mod u8;
352-
#[path = "num/u16.rs"] pub mod u16;
353-
#[path = "num/u32.rs"] pub mod u32;
354-
#[path = "num/u64.rs"] pub mod u64;
327+
// NB: slice and str are primitive types too, but their module docs + primitive
328+
// doc pages are inlined from the public re-exports of core_collections::{slice,
329+
// str} above.
330+
331+
pub use core::isize;
332+
pub use core::i8;
333+
pub use core::i16;
334+
pub use core::i32;
335+
pub use core::i64;
336+
337+
pub use core::usize;
338+
pub use core::u8;
339+
pub use core::u16;
340+
pub use core::u32;
341+
pub use core::u64;
355342

356343
#[path = "num/f32.rs"] pub mod f32;
357344
#[path = "num/f64.rs"] pub mod f64;

src/libstd/macros.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,15 @@ macro_rules! log {
197197
)
198198
}
199199

200+
#[cfg(test)]
201+
macro_rules! assert_approx_eq {
202+
($a:expr, $b:expr) => ({
203+
let (a, b) = (&$a, &$b);
204+
assert!((*a - *b).abs() < 1.0e-6,
205+
"{} is not approximately equal to {}", *a, *b);
206+
})
207+
}
208+
200209
/// Built-in macros to the compiler itself.
201210
///
202211
/// These macros do not have any corresponding definition with a `macro_rules!`

src/libstd/num/float_macros.rs

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/libstd/num/i16.rs

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/libstd/num/i32.rs

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/libstd/num/i64.rs

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/libstd/num/i8.rs

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/libstd/num/int_macros.rs

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/libstd/num/isize.rs

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/libstd/num/u16.rs

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)