diff options
| author | Ralf Jung <post@ralfj.de> | 2020-09-19 11:47:45 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-09-19 11:47:45 +0200 |
| commit | fef332404341e89e4fe09416d01d82a99f7e8c5f (patch) | |
| tree | 9fb63fad47aa4ea910f186ced17b03e27c5b2729 /compiler/rustc_data_structures/src | |
| parent | 1720fd94e8aafc0e24a537688fe88cb1fd14831e (diff) | |
| parent | 1bfe5efe8f635268646da91f1f4f6e616104b71f (diff) | |
| download | rust-fef332404341e89e4fe09416d01d82a99f7e8c5f.tar.gz rust-fef332404341e89e4fe09416d01d82a99f7e8c5f.zip | |
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`.
Diffstat (limited to 'compiler/rustc_data_structures/src')
| -rw-r--r-- | compiler/rustc_data_structures/src/lib.rs | 1 | ||||
| -rw-r--r-- | compiler/rustc_data_structures/src/tagged_ptr/copy.rs | 2 |
2 files changed, 2 insertions, 1 deletions
diff --git a/compiler/rustc_data_structures/src/lib.rs b/compiler/rustc_data_structures/src/lib.rs index 88c160e93b6..06718cc9803 100644 --- a/compiler/rustc_data_structures/src/lib.rs +++ b/compiler/rustc_data_structures/src/lib.rs @@ -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)] diff --git a/compiler/rustc_data_structures/src/tagged_ptr/copy.rs b/compiler/rustc_data_structures/src/tagged_ptr/copy.rs index d39d146db31..d63bcdb3c2b 100644 --- a/compiler/rustc_data_structures/src/tagged_ptr/copy.rs +++ b/compiler/rustc_data_structures/src/tagged_ptr/copy.rs @@ -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 |
