1313//! The tag must implement the `Tag` trait. We assert that the tag and `Pointer`
1414//! are compatible at compile time.
1515
16- use std:: mem:: ManuallyDrop ;
16+ use std:: mem:: { self , ManuallyDrop } ;
1717use std:: ops:: Deref ;
1818use std:: rc:: Rc ;
1919use std:: sync:: Arc ;
@@ -104,14 +104,17 @@ pub unsafe trait Tag: Copy {
104104
105105unsafe impl < T > Pointer for Box < T > {
106106 const BITS : usize = bits_for :: < Self :: Target > ( ) ;
107+
107108 #[ inline]
108109 fn into_usize ( self ) -> usize {
109110 Box :: into_raw ( self ) as usize
110111 }
112+
111113 #[ inline]
112114 unsafe fn from_usize ( ptr : usize ) -> Self {
113115 Box :: from_raw ( ptr as * mut T )
114116 }
117+
115118 unsafe fn with_ref < R , F : FnOnce ( & Self ) -> R > ( ptr : usize , f : F ) -> R {
116119 let raw = ManuallyDrop :: new ( Self :: from_usize ( ptr) ) ;
117120 f ( & raw )
@@ -120,14 +123,17 @@ unsafe impl<T> Pointer for Box<T> {
120123
121124unsafe impl < T > Pointer for Rc < T > {
122125 const BITS : usize = bits_for :: < Self :: Target > ( ) ;
126+
123127 #[ inline]
124128 fn into_usize ( self ) -> usize {
125129 Rc :: into_raw ( self ) as usize
126130 }
131+
127132 #[ inline]
128133 unsafe fn from_usize ( ptr : usize ) -> Self {
129134 Rc :: from_raw ( ptr as * const T )
130135 }
136+
131137 unsafe fn with_ref < R , F : FnOnce ( & Self ) -> R > ( ptr : usize , f : F ) -> R {
132138 let raw = ManuallyDrop :: new ( Self :: from_usize ( ptr) ) ;
133139 f ( & raw )
@@ -136,14 +142,17 @@ unsafe impl<T> Pointer for Rc<T> {
136142
137143unsafe impl < T > Pointer for Arc < T > {
138144 const BITS : usize = bits_for :: < Self :: Target > ( ) ;
145+
139146 #[ inline]
140147 fn into_usize ( self ) -> usize {
141148 Arc :: into_raw ( self ) as usize
142149 }
150+
143151 #[ inline]
144152 unsafe fn from_usize ( ptr : usize ) -> Self {
145153 Arc :: from_raw ( ptr as * const T )
146154 }
155+
147156 unsafe fn with_ref < R , F : FnOnce ( & Self ) -> R > ( ptr : usize , f : F ) -> R {
148157 let raw = ManuallyDrop :: new ( Self :: from_usize ( ptr) ) ;
149158 f ( & raw )
@@ -152,14 +161,17 @@ unsafe impl<T> Pointer for Arc<T> {
152161
153162unsafe impl < ' a , T : ' a > Pointer for & ' a T {
154163 const BITS : usize = bits_for :: < Self :: Target > ( ) ;
164+
155165 #[ inline]
156166 fn into_usize ( self ) -> usize {
157167 self as * const T as usize
158168 }
169+
159170 #[ inline]
160171 unsafe fn from_usize ( ptr : usize ) -> Self {
161172 & * ( ptr as * const T )
162173 }
174+
163175 unsafe fn with_ref < R , F : FnOnce ( & Self ) -> R > ( ptr : usize , f : F ) -> R {
164176 f ( & * ( & ptr as * const usize as * const Self ) )
165177 }
@@ -183,7 +195,7 @@ unsafe impl<'a, T: 'a> Pointer for &'a mut T {
183195/// Returns the number of bits available for use for tags in a pointer to `T`
184196/// (this is based on `T`'s alignment).
185197pub const fn bits_for < T > ( ) -> usize {
186- let bits = std :: mem:: align_of :: < T > ( ) . trailing_zeros ( ) ;
198+ let bits = mem:: align_of :: < T > ( ) . trailing_zeros ( ) ;
187199
188200 // This is a replacement for `.try_into().unwrap()` unavailable in `const`
189201 // (it's fine to make an assert here, since this is only called in compile time)
0 commit comments