diff --git a/compiler/rustc_data_structures/src/tagged_ptr.rs b/compiler/rustc_data_structures/src/tagged_ptr.rs index a25046986cc59..2914eece6796b 100644 --- a/compiler/rustc_data_structures/src/tagged_ptr.rs +++ b/compiler/rustc_data_structures/src/tagged_ptr.rs @@ -155,7 +155,9 @@ pub const fn bits_for_tags(mut tags: &[usize]) -> u32 { while let &[tag, ref rest @ ..] = tags { tags = rest; - let b = bits_for_tag(tag); + // bits required to represent `tag`, + // position of the most significant 1 + let b = usize::BITS - tag.leading_zeros(); if b > bits { bits = b; } @@ -164,18 +166,6 @@ pub const fn bits_for_tags(mut tags: &[usize]) -> u32 { bits } -/// Returns `(size_of::() * 8) - tag.leading_zeros()` -const fn bits_for_tag(mut tag: usize) -> u32 { - let mut bits = 0; - - while tag > 0 { - bits += 1; - tag >>= 1; - } - - bits -} - unsafe impl Pointer for Box { const BITS: u32 = bits_for::();