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:: { self , ManuallyDrop } ;
16+ use std:: mem:: ManuallyDrop ;
1717use std:: ops:: Deref ;
1818use std:: ptr:: NonNull ;
1919use std:: rc:: Rc ;
2020use std:: sync:: Arc ;
2121
22+ use crate :: aligned:: Aligned ;
23+
2224mod copy;
2325mod drop;
2426
@@ -31,8 +33,7 @@ pub use drop::TaggedPtr;
3133/// # Safety
3234///
3335/// The pointer returned from [`into_ptr`] must be a [valid], pointer to
34- /// [`<Self as Deref>::Target`]. Note that pointers to [`Self::Target`] must be
35- /// thin, even though [`Self::Target`] may not be `Sized`.
36+ /// [`<Self as Deref>::Target`].
3637///
3738/// Note that if `Self` implements [`DerefMut`] the pointer returned from
3839/// [`into_ptr`] must be valid for writes (and thus calling [`NonNull::as_mut`]
@@ -110,7 +111,7 @@ pub unsafe trait Tag: Copy {
110111 unsafe fn from_usize ( tag : usize ) -> Self ;
111112}
112113
113- unsafe impl < T > Pointer for Box < T > {
114+ unsafe impl < T : ? Sized + Aligned > Pointer for Box < T > {
114115 const BITS : usize = bits_for :: < Self :: Target > ( ) ;
115116
116117 #[ inline]
@@ -130,7 +131,7 @@ unsafe impl<T> Pointer for Box<T> {
130131 }
131132}
132133
133- unsafe impl < T > Pointer for Rc < T > {
134+ unsafe impl < T : ? Sized + Aligned > Pointer for Rc < T > {
134135 const BITS : usize = bits_for :: < Self :: Target > ( ) ;
135136
136137 #[ inline]
@@ -149,7 +150,7 @@ unsafe impl<T> Pointer for Rc<T> {
149150 }
150151}
151152
152- unsafe impl < T > Pointer for Arc < T > {
153+ unsafe impl < T : ? Sized + Aligned > Pointer for Arc < T > {
153154 const BITS : usize = bits_for :: < Self :: Target > ( ) ;
154155
155156 #[ inline]
@@ -168,7 +169,7 @@ unsafe impl<T> Pointer for Arc<T> {
168169 }
169170}
170171
171- unsafe impl < ' a , T : ' a > Pointer for & ' a T {
172+ unsafe impl < ' a , T : ' a + ? Sized + Aligned > Pointer for & ' a T {
172173 const BITS : usize = bits_for :: < Self :: Target > ( ) ;
173174
174175 #[ inline]
@@ -186,7 +187,7 @@ unsafe impl<'a, T: 'a> Pointer for &'a T {
186187 }
187188}
188189
189- unsafe impl < ' a , T : ' a > Pointer for & ' a mut T {
190+ unsafe impl < ' a , T : ' a + ? Sized + Aligned > Pointer for & ' a mut T {
190191 const BITS : usize = bits_for :: < Self :: Target > ( ) ;
191192
192193 #[ inline]
@@ -206,8 +207,8 @@ unsafe impl<'a, T: 'a> Pointer for &'a mut T {
206207
207208/// Returns the number of bits available for use for tags in a pointer to `T`
208209/// (this is based on `T`'s alignment).
209- pub const fn bits_for < T > ( ) -> usize {
210- let bits = mem :: align_of :: < T > ( ) . trailing_zeros ( ) ;
210+ pub const fn bits_for < T : ? Sized + Aligned > ( ) -> usize {
211+ let bits = crate :: aligned :: align_of :: < T > ( ) . trailing_zeros ( ) ;
211212
212213 // This is a replacement for `.try_into().unwrap()` unavailable in `const`
213214 // (it's fine to make an assert here, since this is only called in compile time)
0 commit comments