Skip to content

Commit

Permalink
fix: add PhantomPinned to State
Browse files Browse the repository at this point in the history
`!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
  • Loading branch information
yvt committed Oct 25, 2021
1 parent 8404a96 commit cef99aa
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ pub use self::lock::*;
/// [module-level documentation]: index.html
pub struct Cryo<'a, T: ?Sized, Lock: crate::Lock> {
state: UnsafeCell<State<T, Lock>>,
_phantom: (PhantomData<&'a T>, PhantomPinned),
_phantom: PhantomData<&'a T>,
}

/// `Cryo` may be moved around multiple threads, and on each thread
Expand Down Expand Up @@ -286,6 +286,7 @@ where
struct State<T: ?Sized, Lock> {
data: NonNull<T>,
lock: Lock,
_phantom: PhantomPinned,
}

/// The lock guard type of [`Cryo`]. This is currently a type alias but might
Expand Down Expand Up @@ -375,8 +376,9 @@ impl<'a, T: ?Sized + 'a, Lock: crate::Lock> Cryo<'a, T, Lock> {
state: UnsafeCell::new(State {
data: NonNull::from(x),
lock: Lock::new(),
_phantom: PhantomPinned,
}),
_phantom: (PhantomData, PhantomPinned),
_phantom: PhantomData,
}
}

Expand Down Expand Up @@ -431,6 +433,7 @@ impl<'a, T: ?Sized + 'a, Lock: crate::Lock> CryoMut<'a, T, Lock> {
state: UnsafeCell::new(State {
data: NonNull::from(x),
lock: Lock::new(),
_phantom: PhantomPinned,
}),
_phantom: (PhantomData, PhantomPinned),
}
Expand Down

0 comments on commit cef99aa

Please sign in to comment.