Move Unpin impl near Drop impl

These traits are closely related. The meaning of Pin<P> when P isn't
Unpin is that in between when P ends up in the pin and when P's Drop
impl begins running, it must not be moved. Moving before the pin, or
moving from within drop once the Drop impl is in progress, are fine.
This commit is contained in:
David Tolnay 2022-09-02 14:22:59 -07:00
parent 9a84aa559f
commit a14eb80ced
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82

View File

@ -112,6 +112,10 @@ where
unsafe impl<T> Send for UniquePtr<T> where T: Send + UniquePtrTarget {} unsafe impl<T> Send for UniquePtr<T> where T: Send + UniquePtrTarget {}
unsafe impl<T> Sync for UniquePtr<T> where T: Sync + UniquePtrTarget {} unsafe impl<T> Sync for UniquePtr<T> where T: Sync + UniquePtrTarget {}
// UniquePtr is not a self-referential type and is safe to move out of a Pin,
// regardless whether the pointer's target is Unpin.
impl<T> Unpin for UniquePtr<T> where T: UniquePtrTarget {}
impl<T> Drop for UniquePtr<T> impl<T> Drop for UniquePtr<T>
where where
T: UniquePtrTarget, T: UniquePtrTarget,
@ -177,10 +181,6 @@ where
} }
} }
// UniquePtr is not a self-referential type and is safe to move out of a Pin,
// regardless whether the pointer's target is Unpin.
impl<T> Unpin for UniquePtr<T> where T: UniquePtrTarget {}
/// Trait bound for types which may be used as the `T` inside of a /// Trait bound for types which may be used as the `T` inside of a
/// `UniquePtr<T>` in generic code. /// `UniquePtr<T>` in generic code.
/// ///