Skip to content

Commit e2e8746

Browse files
fu5haManishearth
authored andcommitted
reword unpin auto impl section
1 parent 82a6817 commit e2e8746

File tree

2 files changed

+20
-26
lines changed

2 files changed

+20
-26
lines changed

library/core/src/marker.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -938,13 +938,13 @@ marker_impls! {
938938
/// mem::replace(&mut *pinned_string, "other".to_string());
939939
/// ```
940940
///
941-
/// This trait is automatically implemented for almost every type. The compiler (and you!) is free
942-
/// to take the conservative stance of marking types as [`Unpin`] by default. This is because if a
943-
/// type implements [`Unpin`], then it is unsound for [`unsafe`] code to assume that type is truly
944-
/// pinned, *even* when viewed through a "pinning" pointer! It is the responsibility of the
945-
/// implementor of [`unsafe`] code that relies upon pinning for soundness to ensure that all the
946-
/// types it expects to be truly pinned do not implement [`Unpin`]. For more details, see the
947-
/// [`pin` module] docs!
941+
/// This trait is automatically implemented for almost every type. The compiler is free
942+
/// to take the conservative stance of marking types as [`Unpin`] so long as all of the types that
943+
/// compose its fields are also [`Unpin`]. This is because if a type implements [`Unpin`], then it
944+
/// is unsound for that type's implementation to rely on pinning-related guarantees for soundness,
945+
/// *even* when viewed through a "pinning" pointer! It is the responsibility of the implementor of
946+
/// a type that relies upon pinning for soundness to ensure that type is *not* marked as [`Unpin`]
947+
/// by adding [`PhantomPinned`] field. For more details, see the [`pin` module] docs.
948948
///
949949
/// [`mem::replace`]: crate::mem::replace "mem replace"
950950
/// [`Pin`]: crate::pin::Pin "Pin"

library/core/src/pin.rs

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@
205205
//! value which does not actually satisfy the invariants that a pinned value must satisfy, and in
206206
//! this way lead undefined behavior even in (from that point) fully safe code. Similarly, using
207207
//! [`unsafe`], one may get access to a bare [`&mut T`] from a [`Pin<Ptr>`] and
208-
//! juse that to invalidly *move* pinned the value out. It is the job of the user of the
208+
//! use that to invalidly *move* pinned the value out. It is the job of the user of the
209209
//! [`unsafe`] parts of the [`Pin`] API to ensure these invariants are not violated.
210210
//!
211211
//! This differs from e.g. [`UnsafeCell`] which changes the semantics of a program's compiled
@@ -336,24 +336,18 @@
336336
//! unsound without being expressed through pinning, and they would then need to not
337337
//! implement [`Unpin`].
338338
//!
339-
//! The compiler (and users!) is free to take the conservative stance of marking types as [`Unpin`]
340-
//! by default. This is because if a type implements [`Unpin`], then it is unsound for [`unsafe`]
341-
//! code to assume that type is truly pinned, *even* when viewed through a "pinning" pointer! It is
342-
//! the responsibility of *the implementor of [`unsafe`] code that relies upon pinning for
343-
//! soundness* (you, in this case!) to ensure that all the types which that code expects to be truly
344-
//! pinned do not implement [`Unpin`].
345-
//!
346-
//! Like other auto-traits, the compiler will automatically determine that a type implements
347-
//! [`Unpin`] if all its fields also implement [`Unpin`]. If you are building a type which consists
348-
//! of only [`Unpin`] types but has an address-sensistive state and thus should not itself
349-
//! implement [`Unpin`], you must opt out of [`Unpin`] via adding a field with the
350-
//! [`PhantomPinned`] marker type, as we did with our latest `AddrTracker` example above. Without
351-
//! doing this, you must not rely on the pinning guarantees to apply to your type!
352-
//!
353-
//! If you have reason to pin a value of a type that implements [`Unpin`] such that pinning-related
354-
//! guarantees actually are respected, you'll need to create your own wrapper type which itself
355-
//! opts out of implementing [`Unpin`] and contains a sub-field with the [`Unpin`] type that you
356-
//! want to pin.
339+
//! The compiler is free to take the conservative stance of marking types as [`Unpin`] so long as
340+
//! all of the types that compose its fields are also [`Unpin`]. This is because if a type
341+
//! implements [`Unpin`], then it is unsound for that type's implementation to rely on
342+
//! pinning-related guarantees for soundness, *even* when viewed through a "pinning" pointer! It is
343+
//! the responsibility of the implementor of a type that relies upon pinning for soundness to
344+
//! ensure that type is *not* marked as [`Unpin`] by adding [`PhantomPinned`] field. This is
345+
//! exactly what we did with our `AddrTracker` example above. Without doing this, you *must not*
346+
//! rely on pinning-related guarantees to apply to your type!
347+
//!
348+
//! If need to truly pin a value of a foreign or built-in type that implements [`Unpin`], you'll
349+
//! need to create your own wrapper type around the [`Unpin`] type you want to pin and then
350+
//! opts-out of [`Unpin`] using [`PhantomPinned`].
357351
//!
358352
//! Exposing access to the inner field which you want to remain pinned must then be carefully
359353
//! considered as well! Remember, exposing a method that gives access to a

0 commit comments

Comments
 (0)