diff options
| author | Mara Bos <m-ou.se@m-ou.se> | 2020-09-08 21:39:13 +0200 |
|---|---|---|
| committer | Mara Bos <m-ou.se@m-ou.se> | 2020-09-19 06:54:42 +0200 |
| commit | 1e2dba1e7cf15442257f2cd3ddfe5d0462ee9102 (patch) | |
| tree | 402ea425d8883c2c501f563220fddf001d0f91c2 /library/alloc/src | |
| parent | 5c30a16fa03efaf87241b363f4323743746c12b0 (diff) | |
| download | rust-1e2dba1e7cf15442257f2cd3ddfe5d0462ee9102.tar.gz rust-1e2dba1e7cf15442257f2cd3ddfe5d0462ee9102.zip | |
Use `T::BITS` instead of `size_of::<T> * 8`.
Diffstat (limited to 'library/alloc/src')
| -rw-r--r-- | library/alloc/src/collections/binary_heap.rs | 4 | ||||
| -rw-r--r-- | library/alloc/src/lib.rs | 1 | ||||
| -rw-r--r-- | library/alloc/src/raw_vec.rs | 2 |
3 files changed, 4 insertions, 3 deletions
diff --git a/library/alloc/src/collections/binary_heap.rs b/library/alloc/src/collections/binary_heap.rs index 24d17fdd880..8a7dd9d4249 100644 --- a/library/alloc/src/collections/binary_heap.rs +++ b/library/alloc/src/collections/binary_heap.rs @@ -146,7 +146,7 @@ use core::fmt; use core::iter::{FromIterator, FusedIterator, InPlaceIterable, SourceIter, TrustedLen}; -use core::mem::{self, size_of, swap, ManuallyDrop}; +use core::mem::{self, swap, ManuallyDrop}; use core::ops::{Deref, DerefMut}; use core::ptr; @@ -617,7 +617,7 @@ impl<T: Ord> BinaryHeap<T> { #[inline(always)] fn log2_fast(x: usize) -> usize { - 8 * size_of::<usize>() - (x.leading_zeros() as usize) - 1 + (usize::BITS - x.leading_zeros() - 1) as usize } // `rebuild` takes O(len1 + len2) operations diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index 7881c101f9f..f3c1eee47c7 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -101,6 +101,7 @@ #![feature(fn_traits)] #![feature(fundamental)] #![feature(inplace_iteration)] +#![feature(int_bits_const)] #![feature(lang_items)] #![feature(layout_for_ptr)] #![feature(libc)] diff --git a/library/alloc/src/raw_vec.rs b/library/alloc/src/raw_vec.rs index 05382d0b559..62675665f03 100644 --- a/library/alloc/src/raw_vec.rs +++ b/library/alloc/src/raw_vec.rs @@ -528,7 +528,7 @@ unsafe impl<#[may_dangle] T, A: AllocRef> Drop for RawVec<T, A> { #[inline] fn alloc_guard(alloc_size: usize) -> Result<(), TryReserveError> { - if mem::size_of::<usize>() < 8 && alloc_size > isize::MAX as usize { + if usize::BITS < 64 && alloc_size > isize::MAX as usize { Err(CapacityOverflow) } else { Ok(()) |
