Skip to content

Commit b1830f1

Browse files
committed
clean up structural pinning
1 parent a573c7c commit b1830f1

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

library/core/src/pin.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -728,17 +728,19 @@
728728
//! "propagates" to this field or not. Pinning that propagates is also called "structural",
729729
//! because it follows the structure of the type.
730730
//!
731-
//! The choice of whether to pin depends on how the type is being used. If [`unsafe`] code
732-
//! that consumes <code>[Pin]\<[&mut Struct][&mut]></code> also needs to take note of
733-
//! the address of the field itself, it may be evidence that that field is structurally
734-
//! pinned. Unfortunately, there are no hard-and-fast rules.
731+
//! This choice depends on what guarantees you need from the field for your [`unsafe`] code to work.
732+
//! If the field is itself address-sensitive, or participates in the parent struct's address
733+
//! sensitivity, it will need to be structurally pinned.
734+
//!
735+
//! A useful test is if [`unsafe`] code that consumes <code>[Pin]\<[&mut Struct][&mut]></code>
736+
//! also needs to take note of the address of the field itself, it may be evidence that that field
737+
//! is structurally pinned. Unfortunately, there are no hard-and-fast rules.
735738
//!
736739
//! ### Choosing pinning *not to be* structural for `field`...
737740
//!
738-
//! While counter-intuitive, it's actually the easier choice: if you do not expose a
739-
//! <code>[Pin]<[&mut] Field></code>, then no code must be written assuming that the field is
740-
//! pinned and so nothing can go wrong. So, if you decide that some field does not
741-
//! have structural pinning, all you have to ensure is that you never create pinning
741+
//! While counter-intuitive, it's often the easier choice: if you do not expose a
742+
//! <code>[Pin]<[&mut] Field></code>, you do not need to be careful about other code
743+
//! moving out of that field, you just have to ensure is that you never create pinning
742744
//! reference to that field. This does of course also mean that if you decide a field does not
743745
//! have structural pinning, you must not write [`unsafe`] code that assumes (invalidly) that the
744746
//! field *is* structurally pinned!

0 commit comments

Comments
 (0)