Rollup merge of #76492 - fusion-engineering-forks:int-bits, r=dtolnay
Add associated constant `BITS` to all integer types Recently I've regularly come across this snippet (in a few different crates, including `core` and `std`): ```rust std::mem::size_of<usize>() * 8 ``` I think it's time for a `usize::BITS`.
This commit is contained in:
commit
fef3324043
18 changed files with 72 additions and 64 deletions
|
@ -14,6 +14,7 @@
|
|||
#![feature(generators)]
|
||||
#![feature(generator_trait)]
|
||||
#![feature(fn_traits)]
|
||||
#![feature(int_bits_const)]
|
||||
#![feature(min_specialization)]
|
||||
#![feature(optin_builtin_traits)]
|
||||
#![feature(nll)]
|
||||
|
|
|
@ -48,7 +48,7 @@ where
|
|||
P: Pointer,
|
||||
T: Tag,
|
||||
{
|
||||
const TAG_BIT_SHIFT: usize = (8 * std::mem::size_of::<usize>()) - T::BITS;
|
||||
const TAG_BIT_SHIFT: usize = usize::BITS as usize - T::BITS;
|
||||
const ASSERTION: () = {
|
||||
assert!(T::BITS <= P::BITS);
|
||||
// Used for the transmute_copy's below
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue