|
753 | 753 | //! 1. *Structural [`Unpin`].* A struct can be [`Unpin`] if, and only if, all of its
|
754 | 754 | //! structurally-pinned fields are, too. This is [`Unpin`]'s behavior by default.
|
755 | 755 | //! However, as a libray author, it is your responsibility not to write something like
|
756 |
| -//! <code>unsafe impl\<T> [Unpin] for Struct\<T> {}</code>. (Adding *any* projection |
757 |
| -//! operation requires unsafe code, so the fact that [`Unpin`] is a safe trait does not break |
758 |
| -//! the principle that you only have to worry about any of this if you use [`unsafe`].) |
| 756 | +//! <code>impl\<T> [Unpin] for Struct\<T> {}</code> and then offer a method that provides |
| 757 | +//! structural pinning to an inner field of `T`, which may not be [`Unpin`]! (Adding *any* |
| 758 | +//! projection operation requires unsafe code, so the fact that [`Unpin`] is a safe trait does |
| 759 | +//! not break the principle that you only have to worry about any of this if you use |
| 760 | +//! [`unsafe`].) |
759 | 761 | //!
|
760 | 762 | //! 2. *Pinned Destruction.* As discussed [above][drop-impl], [`drop`] takes
|
761 | 763 | //! [`&mut self`], but the struct (and hence its fields) might have been pinned
|
|
764 | 766 | //!
|
765 | 767 | //! As a consequence, the struct *must not* be [`#[repr(packed)]`][packed].
|
766 | 768 | //!
|
767 |
| -//! 3. *Structural Notice of Destruction.* You must uphold the the [`Drop` guarantee][drop-guarantee]: |
768 |
| -//! once your struct is pinned, the struct's storage cannot be re-used without calling the |
769 |
| -//! structurally-pinned fields' destructors, as well. |
| 769 | +//! 3. *Structural Notice of Destruction.* You must uphold the the |
| 770 | +//! [`Drop` guarantee][drop-guarantee]: once your struct is pinned, the struct's storage cannot |
| 771 | +//! be re-used without calling the structurally-pinned fields' destructors, as well. |
770 | 772 | //!
|
771 | 773 | //! This can be tricky, as witnessed by [`VecDeque<T>`]: the destructor of [`VecDeque<T>`]
|
772 | 774 | //! can fail to call [`drop`] on all elements if one of the destructors panics. This violates
|
773 |
| -//! the [`Drop` guarantee][drop-guarantee], because it can lead to elements being deallocated without |
774 |
| -//! their destructor being called. |
| 775 | +//! the [`Drop` guarantee][drop-guarantee], because it can lead to elements being deallocated |
| 776 | +//! without their destructor being called. |
775 | 777 | //!
|
776 | 778 | //! [`VecDeque<T>`] has no pinning projections, so its destructor is sound. If it wanted
|
777 | 779 | //! to provide such structural pinning, its destructor would need to abort the process if any
|
|
0 commit comments