diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs index ca86850f5df..2db9cc7c4d8 100644 --- a/src/liballoc/lib.rs +++ b/src/liballoc/lib.rs @@ -83,6 +83,7 @@ #![feature(lang_items)] #![feature(no_std)] #![feature(nonzero)] +#![feature(num_bits_bytes)] #![feature(optin_builtin_traits)] #![feature(placement_in_syntax)] #![feature(placement_new_protocol)] diff --git a/src/liballoc/raw_vec.rs b/src/liballoc/raw_vec.rs index 9311f44d9df..97acd0db524 100644 --- a/src/liballoc/raw_vec.rs +++ b/src/liballoc/raw_vec.rs @@ -15,6 +15,7 @@ use heap; use super::oom; use super::boxed::Box; use core::ops::Drop; +use core; /// A low-level utility for more ergonomically allocating, reallocating, and deallocating a /// a buffer of memory on the heap without having to worry about all the corner cases @@ -443,11 +444,8 @@ impl Drop for RawVec { // user-space. e.g. PAE or x32 #[inline] -#[cfg(target_pointer_width = "64")] -fn alloc_guard(_alloc_size: usize) { } - -#[inline] -#[cfg(target_pointer_width = "32")] fn alloc_guard(alloc_size: usize) { - assert!(alloc_size <= ::core::isize::MAX as usize, "capacity overflow"); + if core::usize::BITS < 64 { + assert!(alloc_size <= ::core::isize::MAX as usize, "capacity overflow"); + } } diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index ea2a9d1cfaf..86700583f2d 100644 --- a/src/libcore/fmt/mod.rs +++ b/src/libcore/fmt/mod.rs @@ -1340,12 +1340,7 @@ impl Pointer for *const T { f.flags |= 1 << (FlagV1::SignAwareZeroPad as u32); if let None = f.width { - // The formats need two extra bytes, for the 0x - if cfg!(target_pointer_width = "32") { - f.width = Some(10); - } else { - f.width = Some(18); - } + f.width = Some((::usize::BITS/4) + 2); } } f.flags |= 1 << (FlagV1::Alternate as u32); diff --git a/src/libcore/hash/mod.rs b/src/libcore/hash/mod.rs index 361c6d700de..2a4c909d638 100644 --- a/src/libcore/hash/mod.rs +++ b/src/libcore/hash/mod.rs @@ -144,11 +144,11 @@ pub trait Hasher { #[inline] #[stable(feature = "hasher_write", since = "1.3.0")] fn write_usize(&mut self, i: usize) { - if cfg!(target_pointer_width = "32") { - self.write_u32(i as u32) - } else { - self.write_u64(i as u64) - } + let bytes = unsafe { + ::slice::from_raw_parts(&i as *const usize as *const u8, + mem::size_of::()) + }; + self.write(bytes); } /// Write a single `i8` into this hasher. diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index 0471a08cd78..b800ec24a95 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -2234,7 +2234,9 @@ step_impl_signed!(isize i8 i16 i32); step_impl_unsigned!(u64); #[cfg(target_pointer_width = "64")] step_impl_signed!(i64); -#[cfg(target_pointer_width = "32")] +// If the target pointer width is not 64-bits, we +// assume here that it is less than 64-bits. +#[cfg(not(target_pointer_width = "64"))] step_impl_no_between!(u64 i64); /// An adapter for stepping range iterators by a custom amount.