Skip to content

Commit cef99aa

Browse files
committed
fix: add PhantomPinned to State
`!Unpin` is necessary to avoid the `noalias` LLVM attribute on `&mut State`. A similar fix was done recently in Tokio [1]. [1]: tokio-rs/tokio#3654
1 parent 8404a96 commit cef99aa

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/lib.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ pub use self::lock::*;
198198
/// [module-level documentation]: index.html
199199
pub struct Cryo<'a, T: ?Sized, Lock: crate::Lock> {
200200
state: UnsafeCell<State<T, Lock>>,
201-
_phantom: (PhantomData<&'a T>, PhantomPinned),
201+
_phantom: PhantomData<&'a T>,
202202
}
203203

204204
/// `Cryo` may be moved around multiple threads, and on each thread
@@ -286,6 +286,7 @@ where
286286
struct State<T: ?Sized, Lock> {
287287
data: NonNull<T>,
288288
lock: Lock,
289+
_phantom: PhantomPinned,
289290
}
290291

291292
/// The lock guard type of [`Cryo`]. This is currently a type alias but might
@@ -375,8 +376,9 @@ impl<'a, T: ?Sized + 'a, Lock: crate::Lock> Cryo<'a, T, Lock> {
375376
state: UnsafeCell::new(State {
376377
data: NonNull::from(x),
377378
lock: Lock::new(),
379+
_phantom: PhantomPinned,
378380
}),
379-
_phantom: (PhantomData, PhantomPinned),
381+
_phantom: PhantomData,
380382
}
381383
}
382384

@@ -431,6 +433,7 @@ impl<'a, T: ?Sized + 'a, Lock: crate::Lock> CryoMut<'a, T, Lock> {
431433
state: UnsafeCell::new(State {
432434
data: NonNull::from(x),
433435
lock: Lock::new(),
436+
_phantom: PhantomPinned,
434437
}),
435438
_phantom: (PhantomData, PhantomPinned),
436439
}

0 commit comments

Comments
 (0)