@@ -1003,22 +1003,25 @@ impl<P, U> CoerceUnsized<Pin<U>> for Pin<P> where P: CoerceUnsized<U> {}
10031003#[ stable( feature = "pin" , since = "1.33.0" ) ]
10041004impl < P , U > DispatchFromDyn < Pin < U > > for Pin < P > where P : DispatchFromDyn < U > { }
10051005
1006- /// Constructs a <code>[Pin]<[&mut] T></code>, by pinning[^1] a `value: T` _locally_[^2] .
1006+ /// Constructs a <code>[Pin]<[&mut] T></code>, by pinning a `value: T` locally .
10071007///
1008- /// Unlike [`Box::pin`], this does not involve a heap allocation.
1008+ /// Unlike [`Box::pin`], this does not create a new heap allocation. As explained
1009+ /// below, the element might still end up on the heap however.
10091010///
1010- /// [^1]: If the (type `T` of the) given value does not implement [`Unpin`], then this
1011- /// effectively pins the `value` in memory, where it will be unable to be moved.
1012- /// Otherwise, <code>[Pin]<[&mut] T></code> behaves like <code>[&mut] T</code>, and operations such
1013- /// as [`mem::replace()`][crate::mem::replace] will allow extracting that value , and therefore,
1014- /// moving it.
1015- /// See [the `Unpin` section of the `pin` module][self#unpin] for more info .
1011+ /// The local pinning performed by this macro is usually dubbed "stack"-pinning.
1012+ /// Outside of `async` contexts locals do indeed get stored on the stack. In
1013+ /// `async` functions or blocks however, any locals crossing an `.await` point
1014+ /// are part of the state captured by the `Future` , and will use the storage of
1015+ /// those. That storage can either be on the heap or on the stack. Therefore,
1016+ /// local pinning is a more accurate term .
10161017///
1017- /// [^2]: This is usually dubbed "stack"-pinning. And whilst local values are almost always located
1018- /// in the stack (_e.g._, when within the body of a non-`async` function), the truth is that inside
1019- /// the body of an `async fn` or block —more generally, the body of a generator— any locals crossing
1020- /// an `.await` point —a `yield` point— end up being part of the state captured by the `Future` —by
1021- /// the `Generator`—, and thus will be stored wherever that one is.
1018+ /// If the type of the given value does not implement [`Unpin`], then this macro
1019+ /// pins the value in memory in a way that prevents moves. On the other hand,
1020+ /// if the type does implement [`Unpin`], <code>[Pin]<[&mut] T></code> behaves
1021+ /// like <code>[&mut] T</code>, and operations such as
1022+ /// [`mem::replace()`][crate::mem::replace] or [`mem::take()`](crate::mem::take)
1023+ /// will allow moves of the value.
1024+ /// See [the `Unpin` section of the `pin` module][self#unpin] for details.
10221025///
10231026/// ## Examples
10241027///
@@ -1158,9 +1161,9 @@ impl<P, U> DispatchFromDyn<Pin<U>> for Pin<P> where P: DispatchFromDyn<U> {}
11581161///
11591162/// If you really need to return a pinned value, consider using [`Box::pin`] instead.
11601163///
1161- /// On the other hand, pinning to the stack[<sup>2</sup>](#fn2) using [`pin!`] is likely to be
1162- /// cheaper than pinning into a fresh heap allocation using [`Box::pin`]. Moreover, by virtue of not
1163- /// even needing an allocator, [`pin!`] is the main non-`unsafe` `#![no_std]`-compatible [`Pin`]
1164+ /// On the other hand, local pinning using [`pin!`] is likely to be cheaper than
1165+ /// pinning into a fresh heap allocation using [`Box::pin`]. Moreover, by virtue of not
1166+ /// requiring an allocator, [`pin!`] is the main non-`unsafe` `#![no_std]`-compatible [`Pin`]
11641167/// constructor.
11651168///
11661169/// [`Box::pin`]: ../../std/boxed/struct.Box.html#method.pin
0 commit comments