@@ -70,13 +70,13 @@ pub unsafe trait Pointer: Deref {
7070 /// # struct T;
7171 /// # impl Deref for T { type Target = u8; fn deref(&self) -> &u8 { &0 } }
7272 /// # impl T {
73- /// const BITS: usize = bits_for::<<Self as Deref>::Target>();
73+ /// const BITS: u32 = bits_for::<<Self as Deref>::Target>();
7474 /// # }
7575 /// ```
7676 ///
7777 /// [`BITS`]: Pointer::BITS
7878 /// [`Self::Target`]: Deref::Target
79- const BITS : usize ;
79+ const BITS : u32 ;
8080
8181 /// Turns this pointer into a raw, non-null pointer.
8282 ///
@@ -118,7 +118,7 @@ pub unsafe trait Tag: Copy {
118118 /// value.
119119 ///
120120 /// [`into_usize`]: Tag::into_usize
121- const BITS : usize ;
121+ const BITS : u32 ;
122122
123123 /// Turns this tag into an integer.
124124 ///
@@ -142,7 +142,7 @@ pub unsafe trait Tag: Copy {
142142}
143143
144144unsafe impl < T : ?Sized + Aligned > Pointer for Box < T > {
145- const BITS : usize = bits_for :: < Self :: Target > ( ) ;
145+ const BITS : u32 = bits_for :: < Self :: Target > ( ) ;
146146
147147 #[ inline]
148148 fn into_ptr ( self ) -> NonNull < T > {
@@ -158,7 +158,7 @@ unsafe impl<T: ?Sized + Aligned> Pointer for Box<T> {
158158}
159159
160160unsafe impl < T : ?Sized + Aligned > Pointer for Rc < T > {
161- const BITS : usize = bits_for :: < Self :: Target > ( ) ;
161+ const BITS : u32 = bits_for :: < Self :: Target > ( ) ;
162162
163163 #[ inline]
164164 fn into_ptr ( self ) -> NonNull < T > {
@@ -174,7 +174,7 @@ unsafe impl<T: ?Sized + Aligned> Pointer for Rc<T> {
174174}
175175
176176unsafe impl < T : ?Sized + Aligned > Pointer for Arc < T > {
177- const BITS : usize = bits_for :: < Self :: Target > ( ) ;
177+ const BITS : u32 = bits_for :: < Self :: Target > ( ) ;
178178
179179 #[ inline]
180180 fn into_ptr ( self ) -> NonNull < T > {
@@ -190,7 +190,7 @@ unsafe impl<T: ?Sized + Aligned> Pointer for Arc<T> {
190190}
191191
192192unsafe impl < ' a , T : ' a + ?Sized + Aligned > Pointer for & ' a T {
193- const BITS : usize = bits_for :: < Self :: Target > ( ) ;
193+ const BITS : u32 = bits_for :: < Self :: Target > ( ) ;
194194
195195 #[ inline]
196196 fn into_ptr ( self ) -> NonNull < T > {
@@ -206,7 +206,7 @@ unsafe impl<'a, T: 'a + ?Sized + Aligned> Pointer for &'a T {
206206}
207207
208208unsafe impl < ' a , T : ' a + ?Sized + Aligned > Pointer for & ' a mut T {
209- const BITS : usize = bits_for :: < Self :: Target > ( ) ;
209+ const BITS : u32 = bits_for :: < Self :: Target > ( ) ;
210210
211211 #[ inline]
212212 fn into_ptr ( self ) -> NonNull < T > {
@@ -223,14 +223,8 @@ unsafe impl<'a, T: 'a + ?Sized + Aligned> Pointer for &'a mut T {
223223
224224/// Returns the number of bits available for use for tags in a pointer to `T`
225225/// (this is based on `T`'s alignment).
226- pub const fn bits_for < T : ?Sized + Aligned > ( ) -> usize {
227- let bits = crate :: aligned:: align_of :: < T > ( ) . trailing_zeros ( ) ;
228-
229- // This is a replacement for `.try_into().unwrap()` unavailable in `const`
230- // (it's fine to make an assert here, since this is only called in compile time)
231- assert ! ( ( bits as u128 ) < usize :: MAX as u128 ) ;
232-
233- bits as usize
226+ pub const fn bits_for < T : ?Sized + Aligned > ( ) -> u32 {
227+ crate :: aligned:: align_of :: < T > ( ) . as_nonzero ( ) . trailing_zeros ( )
234228}
235229
236230/// A tag type used in [`CopyTaggedPtr`] and [`TaggedPtr`] tests.
@@ -245,7 +239,7 @@ enum Tag2 {
245239
246240#[ cfg( test) ]
247241unsafe impl Tag for Tag2 {
248- const BITS : usize = 2 ;
242+ const BITS : u32 = 2 ;
249243
250244 fn into_usize ( self ) -> usize {
251245 self as _
0 commit comments