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
@@ -1050,15 +1050,15 @@ use crate::{
10501050#[ fundamental]
10511051#[ repr( transparent) ]
10521052#[ derive( Copy , Clone ) ]
1053- pub struct Pin < P > {
1053+ pub struct Pin < Ptr > {
10541054 // FIXME(#93176): this field is made `#[unstable] #[doc(hidden)] pub` to:
10551055 // - deter downstream users from accessing it (which would be unsound!),
10561056 // - let the `pin!` macro access it (such a macro requires using struct
10571057 // literal syntax in order to benefit from lifetime extension).
10581058 // Long-term, `unsafe` fields or macro hygiene are expected to offer more robust alternatives.
10591059 #[ unstable( feature = "unsafe_pin_internals" , issue = "none" ) ]
10601060 #[ doc( hidden) ]
1061- pub pointer : P ,
1061+ pub pointer : Ptr ,
10621062}
10631063
10641064// The following implementations aren't derived in order to avoid soundness
@@ -1068,68 +1068,68 @@ pub struct Pin<P> {
10681068// See <https://internals.rust-lang.org/t/unsoundness-in-pin/11311/73> for more details.
10691069
10701070#[ stable( feature = "pin_trait_impls" , since = "1.41.0" ) ]
1071- impl < P : Deref , Q : Deref > PartialEq < Pin < Q > > for Pin < P >
1071+ impl < Ptr : Deref , Q : Deref > PartialEq < Pin < Q > > for Pin < Ptr >
10721072where
1073- P :: Target : PartialEq < Q :: Target > ,
1073+ Ptr :: Target : PartialEq < Q :: Target > ,
10741074{
10751075 fn eq ( & self , other : & Pin < Q > ) -> bool {
1076- P :: Target :: eq ( self , other)
1076+ Ptr :: Target :: eq ( self , other)
10771077 }
10781078
10791079 fn ne ( & self , other : & Pin < Q > ) -> bool {
1080- P :: Target :: ne ( self , other)
1080+ Ptr :: Target :: ne ( self , other)
10811081 }
10821082}
10831083
10841084#[ stable( feature = "pin_trait_impls" , since = "1.41.0" ) ]
1085- impl < P : Deref < Target : Eq > > Eq for Pin < P > { }
1085+ impl < Ptr : Deref < Target : Eq > > Eq for Pin < Ptr > { }
10861086
10871087#[ stable( feature = "pin_trait_impls" , since = "1.41.0" ) ]
1088- impl < P : Deref , Q : Deref > PartialOrd < Pin < Q > > for Pin < P >
1088+ impl < Ptr : Deref , Q : Deref > PartialOrd < Pin < Q > > for Pin < Ptr >
10891089where
1090- P :: Target : PartialOrd < Q :: Target > ,
1090+ Ptr :: Target : PartialOrd < Q :: Target > ,
10911091{
10921092 fn partial_cmp ( & self , other : & Pin < Q > ) -> Option < cmp:: Ordering > {
1093- P :: Target :: partial_cmp ( self , other)
1093+ Ptr :: Target :: partial_cmp ( self , other)
10941094 }
10951095
10961096 fn lt ( & self , other : & Pin < Q > ) -> bool {
1097- P :: Target :: lt ( self , other)
1097+ Ptr :: Target :: lt ( self , other)
10981098 }
10991099
11001100 fn le ( & self , other : & Pin < Q > ) -> bool {
1101- P :: Target :: le ( self , other)
1101+ Ptr :: Target :: le ( self , other)
11021102 }
11031103
11041104 fn gt ( & self , other : & Pin < Q > ) -> bool {
1105- P :: Target :: gt ( self , other)
1105+ Ptr :: Target :: gt ( self , other)
11061106 }
11071107
11081108 fn ge ( & self , other : & Pin < Q > ) -> bool {
1109- P :: Target :: ge ( self , other)
1109+ Ptr :: Target :: ge ( self , other)
11101110 }
11111111}
11121112
11131113#[ stable( feature = "pin_trait_impls" , since = "1.41.0" ) ]
1114- impl < P : Deref < Target : Ord > > Ord for Pin < P > {
1114+ impl < Ptr : Deref < Target : Ord > > Ord for Pin < Ptr > {
11151115 fn cmp ( & self , other : & Self ) -> cmp:: Ordering {
1116- P :: Target :: cmp ( self , other)
1116+ Ptr :: Target :: cmp ( self , other)
11171117 }
11181118}
11191119
11201120#[ stable( feature = "pin_trait_impls" , since = "1.41.0" ) ]
1121- impl < P : Deref < Target : Hash > > Hash for Pin < P > {
1121+ impl < Ptr : Deref < Target : Hash > > Hash for Pin < Ptr > {
11221122 fn hash < H : Hasher > ( & self , state : & mut H ) {
1123- P :: Target :: hash ( self , state) ;
1123+ Ptr :: Target :: hash ( self , state) ;
11241124 }
11251125}
11261126
1127- impl < P : Deref < Target : Unpin > > Pin < P > {
1128- /// Construct a new `Pin<P >` around a pointer to some data of a type that
1127+ impl < Ptr : Deref < Target : Unpin > > Pin < Ptr > {
1128+ /// Construct a new `Pin<Ptr >` around a pointer to some data of a type that
11291129 /// implements [`Unpin`].
11301130 ///
11311131 /// Unlike `Pin::new_unchecked`, this method is safe because the pointer
1132- /// `P ` dereferences to an [`Unpin`] type, which cancels the pinning guarantees.
1132+ /// `Ptr ` dereferences to an [`Unpin`] type, which cancels the pinning guarantees.
11331133 ///
11341134 /// # Examples
11351135 ///
@@ -1143,16 +1143,16 @@ impl<P: Deref<Target: Unpin>> Pin<P> {
11431143 #[ inline( always) ]
11441144 #[ rustc_const_unstable( feature = "const_pin" , issue = "76654" ) ]
11451145 #[ stable( feature = "pin" , since = "1.33.0" ) ]
1146- pub const fn new ( pointer : P ) -> Pin < P > {
1146+ pub const fn new ( pointer : Ptr ) -> Pin < Ptr > {
11471147 // SAFETY: the value pointed to is `Unpin`, and so has no requirements
11481148 // around pinning.
11491149 unsafe { Pin :: new_unchecked ( pointer) }
11501150 }
11511151
1152- /// Unwraps this `Pin<P>` returning the underlying pointer.
1152+ /// Unwraps this `Pin<Ptr>`, returning the underlying pointer.
11531153 ///
1154- /// This requires that the data inside this `Pin` implements [`Unpin`] so that we
1155- /// can ignore the pinning invariants when unwrapping it.
1154+ /// Doing this operation safely requires that the data pointed at by this pinning pointer
1155+ /// implemts [`Unpin`] so that we can ignore the pinning invariants when unwrapping it.
11561156 ///
11571157 /// # Examples
11581158 ///
@@ -1168,13 +1168,13 @@ impl<P: Deref<Target: Unpin>> Pin<P> {
11681168 #[ inline( always) ]
11691169 #[ rustc_const_unstable( feature = "const_pin" , issue = "76654" ) ]
11701170 #[ stable( feature = "pin_into_inner" , since = "1.39.0" ) ]
1171- pub const fn into_inner ( pin : Pin < P > ) -> P {
1171+ pub const fn into_inner ( pin : Pin < Ptr > ) -> Ptr {
11721172 pin. pointer
11731173 }
11741174}
11751175
1176- impl < P : Deref > Pin < P > {
1177- /// Construct a new `Pin<P >` around a reference to some data of a type that
1176+ impl < Ptr : Deref > Pin < Ptr > {
1177+ /// Construct a new `Pin<Ptr >` around a reference to some data of a type that
11781178 /// may or may not implement `Unpin`.
11791179 ///
11801180 /// If `pointer` dereferences to an `Unpin` type, `Pin::new` should be used
@@ -1184,18 +1184,18 @@ impl<P: Deref> Pin<P> {
11841184 ///
11851185 /// This constructor is unsafe because we cannot guarantee that the data
11861186 /// pointed to by `pointer` is pinned, meaning that the data will not be moved or
1187- /// its storage invalidated until it gets dropped. If the constructed `Pin<P >` does
1188- /// not guarantee that the data `P ` points to is pinned, that is a violation of
1187+ /// its storage invalidated until it gets dropped. If the constructed `Pin<Ptr >` does
1188+ /// not guarantee that the data `Ptr ` points to is pinned, that is a violation of
11891189 /// the API contract and may lead to undefined behavior in later (safe) operations.
11901190 ///
1191- /// By using this method, you are making a promise about the `P ::Deref` and
1192- /// `P ::DerefMut` implementations, if they exist. Most importantly, they
1191+ /// By using this method, you are making a promise about the `Ptr ::Deref` and
1192+ /// `Ptr ::DerefMut` implementations, if they exist. Most importantly, they
11931193 /// must not move out of their `self` arguments: `Pin::as_mut` and `Pin::as_ref`
1194- /// will call `DerefMut::deref_mut` and `Deref::deref` *on the pointer type P *
1194+ /// will call `DerefMut::deref_mut` and `Deref::deref` *on the pointer type `Ptr` *
11951195 /// and expect these methods to uphold the pinning invariants.
1196- /// Moreover, by calling this method you promise that the reference `P `
1196+ /// Moreover, by calling this method you promise that the reference `Ptr `
11971197 /// dereferences to will not be moved out of again; in particular, it
1198- /// must not be possible to obtain a `&mut P ::Target` and then
1198+ /// must not be possible to obtain a `&mut Ptr ::Target` and then
11991199 /// move out of that reference (using, for example [`mem::swap`]).
12001200 ///
12011201 /// For example, calling `Pin::new_unchecked` on an `&'a mut T` is unsafe because
@@ -1299,7 +1299,7 @@ impl<P: Deref> Pin<P> {
12991299 #[ inline( always) ]
13001300 #[ rustc_const_unstable( feature = "const_pin" , issue = "76654" ) ]
13011301 #[ stable( feature = "pin" , since = "1.33.0" ) ]
1302- pub const unsafe fn new_unchecked ( pointer : P ) -> Pin < P > {
1302+ pub const unsafe fn new_unchecked ( pointer : Ptr ) -> Pin < Ptr > {
13031303 Pin { pointer }
13041304 }
13051305
@@ -1312,34 +1312,39 @@ impl<P: Deref> Pin<P> {
13121312 /// ruled out by the contract of `Pin::new_unchecked`.
13131313 #[ stable( feature = "pin" , since = "1.33.0" ) ]
13141314 #[ inline( always) ]
1315- pub fn as_ref ( & self ) -> Pin < & P :: Target > {
1315+ pub fn as_ref ( & self ) -> Pin < & Ptr :: Target > {
13161316 // SAFETY: see documentation on this function
13171317 unsafe { Pin :: new_unchecked ( & * self . pointer ) }
13181318 }
13191319
1320- /// Unwraps this `Pin<P >` returning the underlying pointer.
1320+ /// Unwraps this `Pin<Ptr >` returning the underlying pointer.
13211321 ///
13221322 /// # Safety
13231323 ///
13241324 /// This function is unsafe. You must guarantee that you will continue to
1325- /// treat the pointer `P ` as pinned after you call this function, so that
1325+ /// treat the pointer `Ptr ` as pinned after you call this function, so that
13261326 /// the invariants on the `Pin` type can be upheld. If the code using the
1327- /// resulting `P ` does not continue to maintain the pinning invariants that
1327+ /// resulting `Ptr ` does not continue to maintain the pinning invariants that
13281328 /// is a violation of the API contract and may lead to undefined behavior in
13291329 /// later (safe) operations.
13301330 ///
1331+ /// Note that you must be able to guarantee that the data pointed to by `Ptr`
1332+ /// will be treated as pinned all the way until its `drop` handler is complete!
1333+ ///
1334+ /// *For more information, see the [`pin` module docs][self]*
1335+ ///
13311336 /// If the underlying data is [`Unpin`], [`Pin::into_inner`] should be used
13321337 /// instead.
13331338 #[ inline( always) ]
13341339 #[ rustc_const_unstable( feature = "const_pin" , issue = "76654" ) ]
13351340 #[ stable( feature = "pin_into_inner" , since = "1.39.0" ) ]
1336- pub const unsafe fn into_inner_unchecked ( pin : Pin < P > ) -> P {
1341+ pub const unsafe fn into_inner_unchecked ( pin : Pin < Ptr > ) -> Ptr {
13371342 pin. pointer
13381343 }
13391344}
13401345
1341- impl < P : DerefMut > Pin < P > {
1342- /// Gets a mutable reference to the pinned value this `Pin<P >` points to.
1346+ impl < Ptr : DerefMut > Pin < Ptr > {
1347+ /// Gets a mutable reference to the pinned value this `Pin<Ptr >` points to.
13431348 ///
13441349 /// This is a generic method to go from `&mut Pin<Pointer<T>>` to `Pin<&mut T>`.
13451350 /// It is safe because, as part of the contract of `Pin::new_unchecked`,
@@ -1370,12 +1375,12 @@ impl<P: DerefMut> Pin<P> {
13701375 /// ```
13711376 #[ stable( feature = "pin" , since = "1.33.0" ) ]
13721377 #[ inline( always) ]
1373- pub fn as_mut ( & mut self ) -> Pin < & mut P :: Target > {
1378+ pub fn as_mut ( & mut self ) -> Pin < & mut Ptr :: Target > {
13741379 // SAFETY: see documentation on this function
13751380 unsafe { Pin :: new_unchecked ( & mut * self . pointer ) }
13761381 }
13771382
1378- /// Assigns a new value to the memory location pointed to by the `Pin<P >`.
1383+ /// Assigns a new value to the memory location pointed to by the `Pin<Ptr >`.
13791384 ///
13801385 /// This overwrites pinned data, but that is okay: the original pinned value's destructor gets
13811386 /// run before being overwritten and the new value is also a valid value of the same type, so
@@ -1397,9 +1402,9 @@ impl<P: DerefMut> Pin<P> {
13971402 /// [subtle-details]: self#subtle-details-and-the-drop-guarantee
13981403 #[ stable( feature = "pin" , since = "1.33.0" ) ]
13991404 #[ inline( always) ]
1400- pub fn set ( & mut self , value : P :: Target )
1405+ pub fn set ( & mut self , value : Ptr :: Target )
14011406 where
1402- P :: Target : Sized ,
1407+ Ptr :: Target : Sized ,
14031408 {
14041409 * ( self . pointer ) = value;
14051410 }
@@ -1555,41 +1560,42 @@ impl<T: ?Sized> Pin<&'static T> {
15551560 }
15561561}
15571562
1558- impl < ' a , P : DerefMut > Pin < & ' a mut Pin < P > > {
1563+ impl < ' a , Ptr : DerefMut > Pin < & ' a mut Pin < Ptr > > {
15591564 /// Gets `Pin<&mut T>` to the underlying pinned value from this nested `Pin`-pointer.
15601565 ///
15611566 /// This is a generic method to go from `Pin<&mut Pin<Pointer<T>>>` to `Pin<&mut T>`. It is
15621567 /// safe because the existence of a `Pin<Pointer<T>>` ensures that the pointee, `T`, cannot
15631568 /// move in the future, and this method does not enable the pointee to move. "Malicious"
1564- /// implementations of `P ::DerefMut` are likewise ruled out by the contract of
1569+ /// implementations of `Ptr ::DerefMut` are likewise ruled out by the contract of
15651570 /// `Pin::new_unchecked`.
15661571 #[ unstable( feature = "pin_deref_mut" , issue = "86918" ) ]
15671572 #[ must_use = "`self` will be dropped if the result is not used" ]
15681573 #[ inline( always) ]
1569- pub fn as_deref_mut ( self ) -> Pin < & ' a mut P :: Target > {
1574+ pub fn as_deref_mut ( self ) -> Pin < & ' a mut Ptr :: Target > {
15701575 // SAFETY: What we're asserting here is that going from
15711576 //
1572- // Pin<&mut Pin<P >>
1577+ // Pin<&mut Pin<Ptr >>
15731578 //
15741579 // to
15751580 //
1576- // Pin<&mut P ::Target>
1581+ // Pin<&mut Ptr ::Target>
15771582 //
15781583 // is safe.
15791584 //
15801585 // We need to ensure that two things hold for that to be the case:
15811586 //
1582- // 1) Once we give out a `Pin<&mut P::Target>`, an `&mut P::Target` will not be given out.
1583- // 2) By giving out a `Pin<&mut P::Target>`, we do not risk of violating `Pin<&mut Pin<P>>`
1587+ // 1) Once we give out a `Pin<&mut Ptr::Target>`, an `&mut Ptr::Target` will not be given out.
1588+ // 2) By giving out a `Pin<&mut Ptr::Target>`, we do not risk of violating
1589+ // `Pin<&mut Pin<Ptr>>`
15841590 //
1585- // The existence of `Pin<P >` is sufficient to guarantee #1: since we already have a
1586- // `Pin<P >`, it must already uphold the pinning guarantees, which must mean that
1587- // `Pin<&mut P ::Target>` does as well, since `Pin::as_mut` is safe. We do not have to rely
1588- // on the fact that P is _also_ pinned.
1591+ // The existence of `Pin<Ptr >` is sufficient to guarantee #1: since we already have a
1592+ // `Pin<Ptr >`, it must already uphold the pinning guarantees, which must mean that
1593+ // `Pin<&mut Ptr ::Target>` does as well, since `Pin::as_mut` is safe. We do not have to rely
1594+ // on the fact that `Ptr` is _also_ pinned.
15891595 //
1590- // For #2, we need to ensure that code given a `Pin<&mut P ::Target>` cannot cause the
1591- // `Pin<P >` to move? That is not possible, since `Pin<&mut P ::Target>` no longer retains
1592- // any access to the `P ` itself, much less the `Pin<P >`.
1596+ // For #2, we need to ensure that code given a `Pin<&mut Ptr ::Target>` cannot cause the
1597+ // `Pin<Ptr >` to move? That is not possible, since `Pin<&mut Ptr ::Target>` no longer retains
1598+ // any access to the `Ptr ` itself, much less the `Pin<Ptr >`.
15931599 unsafe { self . get_unchecked_mut ( ) } . as_mut ( )
15941600 }
15951601}
@@ -1609,39 +1615,39 @@ impl<T: ?Sized> Pin<&'static mut T> {
16091615}
16101616
16111617#[ stable( feature = "pin" , since = "1.33.0" ) ]
1612- impl < P : Deref > Deref for Pin < P > {
1613- type Target = P :: Target ;
1614- fn deref ( & self ) -> & P :: Target {
1618+ impl < Ptr : Deref > Deref for Pin < Ptr > {
1619+ type Target = Ptr :: Target ;
1620+ fn deref ( & self ) -> & Ptr :: Target {
16151621 Pin :: get_ref ( Pin :: as_ref ( self ) )
16161622 }
16171623}
16181624
16191625#[ stable( feature = "pin" , since = "1.33.0" ) ]
1620- impl < P : DerefMut < Target : Unpin > > DerefMut for Pin < P > {
1621- fn deref_mut ( & mut self ) -> & mut P :: Target {
1626+ impl < Ptr : DerefMut < Target : Unpin > > DerefMut for Pin < Ptr > {
1627+ fn deref_mut ( & mut self ) -> & mut Ptr :: Target {
16221628 Pin :: get_mut ( Pin :: as_mut ( self ) )
16231629 }
16241630}
16251631
16261632#[ unstable( feature = "receiver_trait" , issue = "none" ) ]
1627- impl < P : Receiver > Receiver for Pin < P > { }
1633+ impl < Ptr : Receiver > Receiver for Pin < Ptr > { }
16281634
16291635#[ stable( feature = "pin" , since = "1.33.0" ) ]
1630- impl < P : fmt:: Debug > fmt:: Debug for Pin < P > {
1636+ impl < Ptr : fmt:: Debug > fmt:: Debug for Pin < Ptr > {
16311637 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
16321638 fmt:: Debug :: fmt ( & self . pointer , f)
16331639 }
16341640}
16351641
16361642#[ stable( feature = "pin" , since = "1.33.0" ) ]
1637- impl < P : fmt:: Display > fmt:: Display for Pin < P > {
1643+ impl < Ptr : fmt:: Display > fmt:: Display for Pin < Ptr > {
16381644 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
16391645 fmt:: Display :: fmt ( & self . pointer , f)
16401646 }
16411647}
16421648
16431649#[ stable( feature = "pin" , since = "1.33.0" ) ]
1644- impl < P : fmt:: Pointer > fmt:: Pointer for Pin < P > {
1650+ impl < Ptr : fmt:: Pointer > fmt:: Pointer for Pin < Ptr > {
16451651 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
16461652 fmt:: Pointer :: fmt ( & self . pointer , f)
16471653 }
@@ -1653,10 +1659,10 @@ impl<P: fmt::Pointer> fmt::Pointer for Pin<P> {
16531659// for other reasons, though, so we just need to take care not to allow such
16541660// impls to land in std.
16551661#[ stable( feature = "pin" , since = "1.33.0" ) ]
1656- impl < P , U > CoerceUnsized < Pin < U > > for Pin < P > where P : CoerceUnsized < U > { }
1662+ impl < Ptr , U > CoerceUnsized < Pin < U > > for Pin < Ptr > where Ptr : CoerceUnsized < U > { }
16571663
16581664#[ stable( feature = "pin" , since = "1.33.0" ) ]
1659- impl < P , U > DispatchFromDyn < Pin < U > > for Pin < P > where P : DispatchFromDyn < U > { }
1665+ impl < Ptr , U > DispatchFromDyn < Pin < U > > for Pin < Ptr > where Ptr : DispatchFromDyn < U > { }
16601666
16611667/// Constructs a <code>[Pin]<[&mut] T></code>, by pinning a `value: T` locally.
16621668///
0 commit comments