@@ -70,13 +70,13 @@ pub unsafe trait Pointer: Deref {
70
70
/// # struct T;
71
71
/// # impl Deref for T { type Target = u8; fn deref(&self) -> &u8 { &0 } }
72
72
/// # impl T {
73
- /// const BITS: usize = bits_for::<<Self as Deref>::Target>();
73
+ /// const BITS: u32 = bits_for::<<Self as Deref>::Target>();
74
74
/// # }
75
75
/// ```
76
76
///
77
77
/// [`BITS`]: Pointer::BITS
78
78
/// [`Self::Target`]: Deref::Target
79
- const BITS : usize ;
79
+ const BITS : u32 ;
80
80
81
81
/// Turns this pointer into a raw, non-null pointer.
82
82
///
@@ -118,7 +118,7 @@ pub unsafe trait Tag: Copy {
118
118
/// value.
119
119
///
120
120
/// [`into_usize`]: Tag::into_usize
121
- const BITS : usize ;
121
+ const BITS : u32 ;
122
122
123
123
/// Turns this tag into an integer.
124
124
///
@@ -142,7 +142,7 @@ pub unsafe trait Tag: Copy {
142
142
}
143
143
144
144
unsafe impl < T : ?Sized + Aligned > Pointer for Box < T > {
145
- const BITS : usize = bits_for :: < Self :: Target > ( ) ;
145
+ const BITS : u32 = bits_for :: < Self :: Target > ( ) ;
146
146
147
147
#[ inline]
148
148
fn into_ptr ( self ) -> NonNull < T > {
@@ -158,7 +158,7 @@ unsafe impl<T: ?Sized + Aligned> Pointer for Box<T> {
158
158
}
159
159
160
160
unsafe impl < T : ?Sized + Aligned > Pointer for Rc < T > {
161
- const BITS : usize = bits_for :: < Self :: Target > ( ) ;
161
+ const BITS : u32 = bits_for :: < Self :: Target > ( ) ;
162
162
163
163
#[ inline]
164
164
fn into_ptr ( self ) -> NonNull < T > {
@@ -174,7 +174,7 @@ unsafe impl<T: ?Sized + Aligned> Pointer for Rc<T> {
174
174
}
175
175
176
176
unsafe impl < T : ?Sized + Aligned > Pointer for Arc < T > {
177
- const BITS : usize = bits_for :: < Self :: Target > ( ) ;
177
+ const BITS : u32 = bits_for :: < Self :: Target > ( ) ;
178
178
179
179
#[ inline]
180
180
fn into_ptr ( self ) -> NonNull < T > {
@@ -190,7 +190,7 @@ unsafe impl<T: ?Sized + Aligned> Pointer for Arc<T> {
190
190
}
191
191
192
192
unsafe 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 > ( ) ;
194
194
195
195
#[ inline]
196
196
fn into_ptr ( self ) -> NonNull < T > {
@@ -206,7 +206,7 @@ unsafe impl<'a, T: 'a + ?Sized + Aligned> Pointer for &'a T {
206
206
}
207
207
208
208
unsafe 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 > ( ) ;
210
210
211
211
#[ inline]
212
212
fn into_ptr ( self ) -> NonNull < T > {
@@ -223,14 +223,8 @@ unsafe impl<'a, T: 'a + ?Sized + Aligned> Pointer for &'a mut T {
223
223
224
224
/// Returns the number of bits available for use for tags in a pointer to `T`
225
225
/// (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 ( )
234
228
}
235
229
236
230
/// A tag type used in [`CopyTaggedPtr`] and [`TaggedPtr`] tests.
@@ -245,7 +239,7 @@ enum Tag2 {
245
239
246
240
#[ cfg( test) ]
247
241
unsafe impl Tag for Tag2 {
248
- const BITS : usize = 2 ;
242
+ const BITS : u32 = 2 ;
249
243
250
244
fn into_usize ( self ) -> usize {
251
245
self as _
0 commit comments