273273//! order to identify the type of the pinned pointee data and provide (restricted) access to it.
274274//!
275275//! A [`Pin<Ptr>`] where [`Ptr: Deref`][Deref] is a "`Ptr`-style pinning pointer" to a pinned
276- //! [`P ::Target`][Target] – so, a <code>[Pin]<[Box]\<T>></code> is an owned, pinning pointer to a
276+ //! [`Ptr ::Target`][Target] – so, a <code>[Pin]<[Box]\<T>></code> is an owned, pinning pointer to a
277277//! pinned `T`, and a <code>[Pin]<[Rc]\<T>></code> is a reference-counted, pinning pointer to a
278278//! pinned `T`.
279279//!
590590//! # Implementing an address-sensitive type.
591591//!
592592//! This section goes into detail on important considerations for implementing your own
593- //! address-sensitive types, which are different from merely using [`Pin<P >`] in a generic
593+ //! address-sensitive types, which are different from merely using [`Pin<Ptr >`] in a generic
594594//! way.
595595//!
596596//! ## Implementing [`Drop`] for types with address-sensitive states
689689//! Even though we can't have the compiler do the assignment for us, it's possible to write
690690//! such specialized functions for types that might need it.
691691//!
692- //! Note that it _is_ possible to assign generically through a [`Pin<P >`] by way of [`Pin::set()`].
692+ //! Note that it _is_ possible to assign generically through a [`Pin<Ptr >`] by way of [`Pin::set()`].
693693//! This does not violate any guarantees, since it will run [`drop`] on the pointee value before
694694//! assigning the new value. Thus, the [`drop`] implementation still has a chance to perform the
695695//! necessary notifications to dependent values before the memory location of the original pinned
@@ -1051,15 +1051,15 @@ use crate::{
10511051#[ fundamental]
10521052#[ repr( transparent) ]
10531053#[ derive( Copy , Clone ) ]
1054- pub struct Pin < P > {
1054+ pub struct Pin < Ptr > {
10551055 // FIXME(#93176): this field is made `#[unstable] #[doc(hidden)] pub` to:
10561056 // - deter downstream users from accessing it (which would be unsound!),
10571057 // - let the `pin!` macro access it (such a macro requires using struct
10581058 // literal syntax in order to benefit from lifetime extension).
10591059 // Long-term, `unsafe` fields or macro hygiene are expected to offer more robust alternatives.
10601060 #[ unstable( feature = "unsafe_pin_internals" , issue = "none" ) ]
10611061 #[ doc( hidden) ]
1062- pub pointer : P ,
1062+ pub pointer : Ptr ,
10631063}
10641064
10651065// The following implementations aren't derived in order to avoid soundness
@@ -1069,68 +1069,68 @@ pub struct Pin<P> {
10691069// See <https://internals.rust-lang.org/t/unsoundness-in-pin/11311/73> for more details.
10701070
10711071#[ stable( feature = "pin_trait_impls" , since = "1.41.0" ) ]
1072- impl < P : Deref , Q : Deref > PartialEq < Pin < Q > > for Pin < P >
1072+ impl < Ptr : Deref , Q : Deref > PartialEq < Pin < Q > > for Pin < Ptr >
10731073where
1074- P :: Target : PartialEq < Q :: Target > ,
1074+ Ptr :: Target : PartialEq < Q :: Target > ,
10751075{
10761076 fn eq ( & self , other : & Pin < Q > ) -> bool {
1077- P :: Target :: eq ( self , other)
1077+ Ptr :: Target :: eq ( self , other)
10781078 }
10791079
10801080 fn ne ( & self , other : & Pin < Q > ) -> bool {
1081- P :: Target :: ne ( self , other)
1081+ Ptr :: Target :: ne ( self , other)
10821082 }
10831083}
10841084
10851085#[ stable( feature = "pin_trait_impls" , since = "1.41.0" ) ]
1086- impl < P : Deref < Target : Eq > > Eq for Pin < P > { }
1086+ impl < Ptr : Deref < Target : Eq > > Eq for Pin < Ptr > { }
10871087
10881088#[ stable( feature = "pin_trait_impls" , since = "1.41.0" ) ]
1089- impl < P : Deref , Q : Deref > PartialOrd < Pin < Q > > for Pin < P >
1089+ impl < Ptr : Deref , Q : Deref > PartialOrd < Pin < Q > > for Pin < Ptr >
10901090where
1091- P :: Target : PartialOrd < Q :: Target > ,
1091+ Ptr :: Target : PartialOrd < Q :: Target > ,
10921092{
10931093 fn partial_cmp ( & self , other : & Pin < Q > ) -> Option < cmp:: Ordering > {
1094- P :: Target :: partial_cmp ( self , other)
1094+ Ptr :: Target :: partial_cmp ( self , other)
10951095 }
10961096
10971097 fn lt ( & self , other : & Pin < Q > ) -> bool {
1098- P :: Target :: lt ( self , other)
1098+ Ptr :: Target :: lt ( self , other)
10991099 }
11001100
11011101 fn le ( & self , other : & Pin < Q > ) -> bool {
1102- P :: Target :: le ( self , other)
1102+ Ptr :: Target :: le ( self , other)
11031103 }
11041104
11051105 fn gt ( & self , other : & Pin < Q > ) -> bool {
1106- P :: Target :: gt ( self , other)
1106+ Ptr :: Target :: gt ( self , other)
11071107 }
11081108
11091109 fn ge ( & self , other : & Pin < Q > ) -> bool {
1110- P :: Target :: ge ( self , other)
1110+ Ptr :: Target :: ge ( self , other)
11111111 }
11121112}
11131113
11141114#[ stable( feature = "pin_trait_impls" , since = "1.41.0" ) ]
1115- impl < P : Deref < Target : Ord > > Ord for Pin < P > {
1115+ impl < Ptr : Deref < Target : Ord > > Ord for Pin < Ptr > {
11161116 fn cmp ( & self , other : & Self ) -> cmp:: Ordering {
1117- P :: Target :: cmp ( self , other)
1117+ Ptr :: Target :: cmp ( self , other)
11181118 }
11191119}
11201120
11211121#[ stable( feature = "pin_trait_impls" , since = "1.41.0" ) ]
1122- impl < P : Deref < Target : Hash > > Hash for Pin < P > {
1122+ impl < Ptr : Deref < Target : Hash > > Hash for Pin < Ptr > {
11231123 fn hash < H : Hasher > ( & self , state : & mut H ) {
1124- P :: Target :: hash ( self , state) ;
1124+ Ptr :: Target :: hash ( self , state) ;
11251125 }
11261126}
11271127
1128- impl < P : Deref < Target : Unpin > > Pin < P > {
1129- /// Construct a new `Pin<P >` around a pointer to some data of a type that
1128+ impl < Ptr : Deref < Target : Unpin > > Pin < Ptr > {
1129+ /// Construct a new `Pin<Ptr >` around a pointer to some data of a type that
11301130 /// implements [`Unpin`].
11311131 ///
11321132 /// Unlike `Pin::new_unchecked`, this method is safe because the pointer
1133- /// `P ` dereferences to an [`Unpin`] type, which cancels the pinning guarantees.
1133+ /// `Ptr ` dereferences to an [`Unpin`] type, which cancels the pinning guarantees.
11341134 ///
11351135 /// # Examples
11361136 ///
@@ -1144,16 +1144,16 @@ impl<P: Deref<Target: Unpin>> Pin<P> {
11441144 #[ inline( always) ]
11451145 #[ rustc_const_unstable( feature = "const_pin" , issue = "76654" ) ]
11461146 #[ stable( feature = "pin" , since = "1.33.0" ) ]
1147- pub const fn new ( pointer : P ) -> Pin < P > {
1147+ pub const fn new ( pointer : Ptr ) -> Pin < Ptr > {
11481148 // SAFETY: the value pointed to is `Unpin`, and so has no requirements
11491149 // around pinning.
11501150 unsafe { Pin :: new_unchecked ( pointer) }
11511151 }
11521152
1153- /// Unwraps this `Pin<P>` returning the underlying pointer.
1153+ /// Unwraps this `Pin<Ptr>`, returning the underlying pointer.
11541154 ///
1155- /// This requires that the data inside this `Pin` implements [`Unpin`] so that we
1156- /// can ignore the pinning invariants when unwrapping it.
1155+ /// Doing this operation safely requires that the data pointed at by this pinning pointer
1156+ /// implemts [`Unpin`] so that we can ignore the pinning invariants when unwrapping it.
11571157 ///
11581158 /// # Examples
11591159 ///
@@ -1169,13 +1169,13 @@ impl<P: Deref<Target: Unpin>> Pin<P> {
11691169 #[ inline( always) ]
11701170 #[ rustc_const_unstable( feature = "const_pin" , issue = "76654" ) ]
11711171 #[ stable( feature = "pin_into_inner" , since = "1.39.0" ) ]
1172- pub const fn into_inner ( pin : Pin < P > ) -> P {
1172+ pub const fn into_inner ( pin : Pin < Ptr > ) -> Ptr {
11731173 pin. pointer
11741174 }
11751175}
11761176
1177- impl < P : Deref > Pin < P > {
1178- /// Construct a new `Pin<P >` around a reference to some data of a type that
1177+ impl < Ptr : Deref > Pin < Ptr > {
1178+ /// Construct a new `Pin<Ptr >` around a reference to some data of a type that
11791179 /// may or may not implement `Unpin`.
11801180 ///
11811181 /// If `pointer` dereferences to an `Unpin` type, `Pin::new` should be used
@@ -1185,18 +1185,18 @@ impl<P: Deref> Pin<P> {
11851185 ///
11861186 /// This constructor is unsafe because we cannot guarantee that the data
11871187 /// pointed to by `pointer` is pinned, meaning that the data will not be moved or
1188- /// its storage invalidated until it gets dropped. If the constructed `Pin<P >` does
1189- /// not guarantee that the data `P ` points to is pinned, that is a violation of
1188+ /// its storage invalidated until it gets dropped. If the constructed `Pin<Ptr >` does
1189+ /// not guarantee that the data `Ptr ` points to is pinned, that is a violation of
11901190 /// the API contract and may lead to undefined behavior in later (safe) operations.
11911191 ///
1192- /// By using this method, you are making a promise about the `P ::Deref` and
1193- /// `P ::DerefMut` implementations, if they exist. Most importantly, they
1192+ /// By using this method, you are making a promise about the `Ptr ::Deref` and
1193+ /// `Ptr ::DerefMut` implementations, if they exist. Most importantly, they
11941194 /// must not move out of their `self` arguments: `Pin::as_mut` and `Pin::as_ref`
1195- /// will call `DerefMut::deref_mut` and `Deref::deref` *on the pointer type P *
1195+ /// will call `DerefMut::deref_mut` and `Deref::deref` *on the pointer type `Ptr` *
11961196 /// and expect these methods to uphold the pinning invariants.
1197- /// Moreover, by calling this method you promise that the reference `P `
1197+ /// Moreover, by calling this method you promise that the reference `Ptr `
11981198 /// dereferences to will not be moved out of again; in particular, it
1199- /// must not be possible to obtain a `&mut P ::Target` and then
1199+ /// must not be possible to obtain a `&mut Ptr ::Target` and then
12001200 /// move out of that reference (using, for example [`mem::swap`]).
12011201 ///
12021202 /// For example, calling `Pin::new_unchecked` on an `&'a mut T` is unsafe because
@@ -1300,7 +1300,7 @@ impl<P: Deref> Pin<P> {
13001300 #[ inline( always) ]
13011301 #[ rustc_const_unstable( feature = "const_pin" , issue = "76654" ) ]
13021302 #[ stable( feature = "pin" , since = "1.33.0" ) ]
1303- pub const unsafe fn new_unchecked ( pointer : P ) -> Pin < P > {
1303+ pub const unsafe fn new_unchecked ( pointer : Ptr ) -> Pin < Ptr > {
13041304 Pin { pointer }
13051305 }
13061306
@@ -1313,34 +1313,39 @@ impl<P: Deref> Pin<P> {
13131313 /// ruled out by the contract of `Pin::new_unchecked`.
13141314 #[ stable( feature = "pin" , since = "1.33.0" ) ]
13151315 #[ inline( always) ]
1316- pub fn as_ref ( & self ) -> Pin < & P :: Target > {
1316+ pub fn as_ref ( & self ) -> Pin < & Ptr :: Target > {
13171317 // SAFETY: see documentation on this function
13181318 unsafe { Pin :: new_unchecked ( & * self . pointer ) }
13191319 }
13201320
1321- /// Unwraps this `Pin<P >` returning the underlying pointer.
1321+ /// Unwraps this `Pin<Ptr >` returning the underlying pointer.
13221322 ///
13231323 /// # Safety
13241324 ///
13251325 /// This function is unsafe. You must guarantee that you will continue to
1326- /// treat the pointer `P ` as pinned after you call this function, so that
1326+ /// treat the pointer `Ptr ` as pinned after you call this function, so that
13271327 /// the invariants on the `Pin` type can be upheld. If the code using the
1328- /// resulting `P ` does not continue to maintain the pinning invariants that
1328+ /// resulting `Ptr ` does not continue to maintain the pinning invariants that
13291329 /// is a violation of the API contract and may lead to undefined behavior in
13301330 /// later (safe) operations.
13311331 ///
1332+ /// Note that you must be able to guarantee that the data pointed to by `Ptr`
1333+ /// will be treated as pinned all the way until its `drop` handler is complete!
1334+ ///
1335+ /// *For more information, see the [`pin` module docs][self]*
1336+ ///
13321337 /// If the underlying data is [`Unpin`], [`Pin::into_inner`] should be used
13331338 /// instead.
13341339 #[ inline( always) ]
13351340 #[ rustc_const_unstable( feature = "const_pin" , issue = "76654" ) ]
13361341 #[ stable( feature = "pin_into_inner" , since = "1.39.0" ) ]
1337- pub const unsafe fn into_inner_unchecked ( pin : Pin < P > ) -> P {
1342+ pub const unsafe fn into_inner_unchecked ( pin : Pin < Ptr > ) -> Ptr {
13381343 pin. pointer
13391344 }
13401345}
13411346
1342- impl < P : DerefMut > Pin < P > {
1343- /// Gets a mutable reference to the pinned value this `Pin<P >` points to.
1347+ impl < Ptr : DerefMut > Pin < Ptr > {
1348+ /// Gets a mutable reference to the pinned value this `Pin<Ptr >` points to.
13441349 ///
13451350 /// This is a generic method to go from `&mut Pin<Pointer<T>>` to `Pin<&mut T>`.
13461351 /// It is safe because, as part of the contract of `Pin::new_unchecked`,
@@ -1371,12 +1376,12 @@ impl<P: DerefMut> Pin<P> {
13711376 /// ```
13721377 #[ stable( feature = "pin" , since = "1.33.0" ) ]
13731378 #[ inline( always) ]
1374- pub fn as_mut ( & mut self ) -> Pin < & mut P :: Target > {
1379+ pub fn as_mut ( & mut self ) -> Pin < & mut Ptr :: Target > {
13751380 // SAFETY: see documentation on this function
13761381 unsafe { Pin :: new_unchecked ( & mut * self . pointer ) }
13771382 }
13781383
1379- /// Assigns a new value to the memory location pointed to by the `Pin<P >`.
1384+ /// Assigns a new value to the memory location pointed to by the `Pin<Ptr >`.
13801385 ///
13811386 /// This overwrites pinned data, but that is okay: the original pinned value's destructor gets
13821387 /// run before being overwritten and the new value is also a valid value of the same type, so
@@ -1398,9 +1403,9 @@ impl<P: DerefMut> Pin<P> {
13981403 /// [subtle-details]: self#subtle-details-and-the-drop-guarantee
13991404 #[ stable( feature = "pin" , since = "1.33.0" ) ]
14001405 #[ inline( always) ]
1401- pub fn set ( & mut self , value : P :: Target )
1406+ pub fn set ( & mut self , value : Ptr :: Target )
14021407 where
1403- P :: Target : Sized ,
1408+ Ptr :: Target : Sized ,
14041409 {
14051410 * ( self . pointer ) = value;
14061411 }
@@ -1556,41 +1561,42 @@ impl<T: ?Sized> Pin<&'static T> {
15561561 }
15571562}
15581563
1559- impl < ' a , P : DerefMut > Pin < & ' a mut Pin < P > > {
1564+ impl < ' a , Ptr : DerefMut > Pin < & ' a mut Pin < Ptr > > {
15601565 /// Gets `Pin<&mut T>` to the underlying pinned value from this nested `Pin`-pointer.
15611566 ///
15621567 /// This is a generic method to go from `Pin<&mut Pin<Pointer<T>>>` to `Pin<&mut T>`. It is
15631568 /// safe because the existence of a `Pin<Pointer<T>>` ensures that the pointee, `T`, cannot
15641569 /// move in the future, and this method does not enable the pointee to move. "Malicious"
1565- /// implementations of `P ::DerefMut` are likewise ruled out by the contract of
1570+ /// implementations of `Ptr ::DerefMut` are likewise ruled out by the contract of
15661571 /// `Pin::new_unchecked`.
15671572 #[ unstable( feature = "pin_deref_mut" , issue = "86918" ) ]
15681573 #[ must_use = "`self` will be dropped if the result is not used" ]
15691574 #[ inline( always) ]
1570- pub fn as_deref_mut ( self ) -> Pin < & ' a mut P :: Target > {
1575+ pub fn as_deref_mut ( self ) -> Pin < & ' a mut Ptr :: Target > {
15711576 // SAFETY: What we're asserting here is that going from
15721577 //
1573- // Pin<&mut Pin<P >>
1578+ // Pin<&mut Pin<Ptr >>
15741579 //
15751580 // to
15761581 //
1577- // Pin<&mut P ::Target>
1582+ // Pin<&mut Ptr ::Target>
15781583 //
15791584 // is safe.
15801585 //
15811586 // We need to ensure that two things hold for that to be the case:
15821587 //
1583- // 1) Once we give out a `Pin<&mut P::Target>`, an `&mut P::Target` will not be given out.
1584- // 2) By giving out a `Pin<&mut P::Target>`, we do not risk of violating `Pin<&mut Pin<P>>`
1588+ // 1) Once we give out a `Pin<&mut Ptr::Target>`, an `&mut Ptr::Target` will not be given out.
1589+ // 2) By giving out a `Pin<&mut Ptr::Target>`, we do not risk of violating
1590+ // `Pin<&mut Pin<Ptr>>`
15851591 //
1586- // The existence of `Pin<P >` is sufficient to guarantee #1: since we already have a
1587- // `Pin<P >`, it must already uphold the pinning guarantees, which must mean that
1588- // `Pin<&mut P ::Target>` does as well, since `Pin::as_mut` is safe. We do not have to rely
1589- // on the fact that P is _also_ pinned.
1592+ // The existence of `Pin<Ptr >` is sufficient to guarantee #1: since we already have a
1593+ // `Pin<Ptr >`, it must already uphold the pinning guarantees, which must mean that
1594+ // `Pin<&mut Ptr ::Target>` does as well, since `Pin::as_mut` is safe. We do not have to rely
1595+ // on the fact that `Ptr` is _also_ pinned.
15901596 //
1591- // For #2, we need to ensure that code given a `Pin<&mut P ::Target>` cannot cause the
1592- // `Pin<P >` to move? That is not possible, since `Pin<&mut P ::Target>` no longer retains
1593- // any access to the `P ` itself, much less the `Pin<P >`.
1597+ // For #2, we need to ensure that code given a `Pin<&mut Ptr ::Target>` cannot cause the
1598+ // `Pin<Ptr >` to move? That is not possible, since `Pin<&mut Ptr ::Target>` no longer retains
1599+ // any access to the `Ptr ` itself, much less the `Pin<Ptr >`.
15941600 unsafe { self . get_unchecked_mut ( ) } . as_mut ( )
15951601 }
15961602}
@@ -1610,39 +1616,39 @@ impl<T: ?Sized> Pin<&'static mut T> {
16101616}
16111617
16121618#[ stable( feature = "pin" , since = "1.33.0" ) ]
1613- impl < P : Deref > Deref for Pin < P > {
1614- type Target = P :: Target ;
1615- fn deref ( & self ) -> & P :: Target {
1619+ impl < Ptr : Deref > Deref for Pin < Ptr > {
1620+ type Target = Ptr :: Target ;
1621+ fn deref ( & self ) -> & Ptr :: Target {
16161622 Pin :: get_ref ( Pin :: as_ref ( self ) )
16171623 }
16181624}
16191625
16201626#[ stable( feature = "pin" , since = "1.33.0" ) ]
1621- impl < P : DerefMut < Target : Unpin > > DerefMut for Pin < P > {
1622- fn deref_mut ( & mut self ) -> & mut P :: Target {
1627+ impl < Ptr : DerefMut < Target : Unpin > > DerefMut for Pin < Ptr > {
1628+ fn deref_mut ( & mut self ) -> & mut Ptr :: Target {
16231629 Pin :: get_mut ( Pin :: as_mut ( self ) )
16241630 }
16251631}
16261632
16271633#[ unstable( feature = "receiver_trait" , issue = "none" ) ]
1628- impl < P : Receiver > Receiver for Pin < P > { }
1634+ impl < Ptr : Receiver > Receiver for Pin < Ptr > { }
16291635
16301636#[ stable( feature = "pin" , since = "1.33.0" ) ]
1631- impl < P : fmt:: Debug > fmt:: Debug for Pin < P > {
1637+ impl < Ptr : fmt:: Debug > fmt:: Debug for Pin < Ptr > {
16321638 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
16331639 fmt:: Debug :: fmt ( & self . pointer , f)
16341640 }
16351641}
16361642
16371643#[ stable( feature = "pin" , since = "1.33.0" ) ]
1638- impl < P : fmt:: Display > fmt:: Display for Pin < P > {
1644+ impl < Ptr : fmt:: Display > fmt:: Display for Pin < Ptr > {
16391645 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
16401646 fmt:: Display :: fmt ( & self . pointer , f)
16411647 }
16421648}
16431649
16441650#[ stable( feature = "pin" , since = "1.33.0" ) ]
1645- impl < P : fmt:: Pointer > fmt:: Pointer for Pin < P > {
1651+ impl < Ptr : fmt:: Pointer > fmt:: Pointer for Pin < Ptr > {
16461652 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
16471653 fmt:: Pointer :: fmt ( & self . pointer , f)
16481654 }
@@ -1654,10 +1660,10 @@ impl<P: fmt::Pointer> fmt::Pointer for Pin<P> {
16541660// for other reasons, though, so we just need to take care not to allow such
16551661// impls to land in std.
16561662#[ stable( feature = "pin" , since = "1.33.0" ) ]
1657- impl < P , U > CoerceUnsized < Pin < U > > for Pin < P > where P : CoerceUnsized < U > { }
1663+ impl < Ptr , U > CoerceUnsized < Pin < U > > for Pin < Ptr > where Ptr : CoerceUnsized < U > { }
16581664
16591665#[ stable( feature = "pin" , since = "1.33.0" ) ]
1660- impl < P , U > DispatchFromDyn < Pin < U > > for Pin < P > where P : DispatchFromDyn < U > { }
1666+ impl < Ptr , U > DispatchFromDyn < Pin < U > > for Pin < Ptr > where Ptr : DispatchFromDyn < U > { }
16611667
16621668/// Constructs a <code>[Pin]<[&mut] T></code>, by pinning a `value: T` locally.
16631669///
0 commit comments