@@ -9,21 +9,15 @@ use std::ptr::NonNull;
99use super :: { Pointer , Tag } ;
1010use crate :: stable_hasher:: { HashStable , StableHasher } ;
1111
12- /// A [`Copy`] tagged pointer.
13- ///
14- /// This is essentially `{ pointer: P, tag: T }` packed in a single pointer.
15- ///
16- /// You should use this instead of the [`TaggedPtr`] type in all cases where
17- /// `P` implements [`Copy`].
12+ /// A covariant [`Copy`] tagged pointer. This is essentially `{ pointer: P, tag: T }` packed
13+ /// in a single pointer.
1814///
1915/// If `COMPARE_PACKED` is true, then the pointers will be compared and hashed without
20- /// unpacking. Otherwise we don't implement [`PartialEq`], [`Eq`] and [`Hash`];
21- /// if you want that, wrap the [`CopyTaggedPtr`].
22- ///
23- /// [`TaggedPtr`]: crate::tagged_ptr::TaggedPtr
24- pub struct CopyTaggedPtr < P , T , const COMPARE_PACKED : bool >
16+ /// unpacking. Otherwise we don't implement [`PartialEq`], [`Eq`] and [`Hash`]; if you
17+ /// want that, wrap the [`TaggedPtr`].
18+ pub struct TaggedPtr < P , Pointee : ?Sized , T , const COMPARE_PACKED : bool >
2519where
26- P : Pointer ,
20+ P : Pointer < Target = Pointee > ,
2721 T : Tag ,
2822{
2923 /// This is semantically a pair of `pointer: P` and `tag: T` fields,
@@ -64,14 +58,14 @@ where
6458 ///
6559 /// The tag can be retrieved by `packed.addr() >> T::BITS` and the pointer
6660 /// can be retrieved by `packed.map_addr(|addr| addr << T::BITS)`.
67- packed : NonNull < P :: Target > ,
68- tag_ghost : PhantomData < T > ,
61+ packed : NonNull < Pointee > ,
62+ tag_pointer_ghost : PhantomData < ( P , T ) > ,
6963}
7064
7165// Note that even though `CopyTaggedPtr` is only really expected to work with
7266// `P: Copy`, can't add `P: Copy` bound, because `CopyTaggedPtr` is used in the
7367// `TaggedPtr`'s implementation.
74- impl < P , T , const CP : bool > CopyTaggedPtr < P , T , CP >
68+ impl < P , T , const CP : bool > TaggedPtr < P , P :: Target , T , CP >
7569where
7670 P : Pointer ,
7771 T : Tag ,
8579 /// [`TaggedPtr`]: crate::tagged_ptr::TaggedPtr
8680 #[ inline]
8781 pub fn new ( pointer : P , tag : T ) -> Self {
88- Self { packed : Self :: pack ( P :: into_ptr ( pointer) , tag) , tag_ghost : PhantomData }
82+ Self { packed : Self :: pack ( P :: into_ptr ( pointer) , tag) , tag_pointer_ghost : PhantomData }
8983 }
9084
9185 /// Retrieves the pointer.
@@ -177,14 +171,14 @@ where
177171 }
178172}
179173
180- impl < P , T , const CP : bool > Copy for CopyTaggedPtr < P , T , CP >
174+ impl < P , T , const CP : bool > Copy for TaggedPtr < P , P :: Target , T , CP >
181175where
182176 P : Pointer + Copy ,
183177 T : Tag ,
184178{
185179}
186180
187- impl < P , T , const CP : bool > Clone for CopyTaggedPtr < P , T , CP >
181+ impl < P , T , const CP : bool > Clone for TaggedPtr < P , P :: Target , T , CP >
188182where
189183 P : Pointer + Copy ,
190184 T : Tag ,
@@ -195,7 +189,7 @@ where
195189 }
196190}
197191
198- impl < P , T , const CP : bool > Deref for CopyTaggedPtr < P , T , CP >
192+ impl < P , T , const CP : bool > Deref for TaggedPtr < P , P :: Target , T , CP >
199193where
200194 P : Pointer ,
201195 T : Tag ,
@@ -211,7 +205,7 @@ where
211205 }
212206}
213207
214- impl < P , T , const CP : bool > DerefMut for CopyTaggedPtr < P , T , CP >
208+ impl < P , T , const CP : bool > DerefMut for TaggedPtr < P , P :: Target , T , CP >
215209where
216210 P : Pointer + DerefMut ,
217211 T : Tag ,
@@ -226,7 +220,7 @@ where
226220 }
227221}
228222
229- impl < P , T , const CP : bool > fmt:: Debug for CopyTaggedPtr < P , T , CP >
223+ impl < P , T , const CP : bool > fmt:: Debug for TaggedPtr < P , P :: Target , T , CP >
230224where
231225 P : Pointer + fmt:: Debug ,
232226 T : Tag + fmt:: Debug ,
@@ -238,7 +232,7 @@ where
238232 }
239233}
240234
241- impl < P , T > PartialEq for CopyTaggedPtr < P , T , true >
235+ impl < P , T > PartialEq for TaggedPtr < P , P :: Target , T , true >
242236where
243237 P : Pointer ,
244238 T : Tag ,
@@ -250,14 +244,14 @@ where
250244 }
251245}
252246
253- impl < P , T > Eq for CopyTaggedPtr < P , T , true >
247+ impl < P , T > Eq for TaggedPtr < P , P :: Target , T , true >
254248where
255249 P : Pointer ,
256250 T : Tag ,
257251{
258252}
259253
260- impl < P , T > Hash for CopyTaggedPtr < P , T , true >
254+ impl < P , T > Hash for TaggedPtr < P , P :: Target , T , true >
261255where
262256 P : Pointer ,
263257 T : Tag ,
@@ -268,7 +262,7 @@ where
268262 }
269263}
270264
271- impl < P , T , HCX , const CP : bool > HashStable < HCX > for CopyTaggedPtr < P , T , CP >
265+ impl < P , T , HCX , const CP : bool > HashStable < HCX > for TaggedPtr < P , P :: Target , T , CP >
272266where
273267 P : Pointer + HashStable < HCX > ,
274268 T : Tag + HashStable < HCX > ,
@@ -282,7 +276,7 @@ where
282276// Safety:
283277// `CopyTaggedPtr<P, T, ..>` is semantically just `{ ptr: P, tag: T }`, as such
284278// it's ok to implement `Sync` as long as `P: Sync, T: Sync`
285- unsafe impl < P , T , const CP : bool > Sync for CopyTaggedPtr < P , T , CP >
279+ unsafe impl < P , T , const CP : bool > Sync for TaggedPtr < P , P :: Target , T , CP >
286280where
287281 P : Sync + Pointer ,
288282 T : Sync + Tag ,
@@ -292,7 +286,7 @@ where
292286// Safety:
293287// `CopyTaggedPtr<P, T, ..>` is semantically just `{ ptr: P, tag: T }`, as such
294288// it's ok to implement `Send` as long as `P: Send, T: Send`
295- unsafe impl < P , T , const CP : bool > Send for CopyTaggedPtr < P , T , CP >
289+ unsafe impl < P , T , const CP : bool > Send for TaggedPtr < P , P :: Target , T , CP >
296290where
297291 P : Send + Pointer ,
298292 T : Send + Tag ,
0 commit comments