@@ -411,14 +411,20 @@ pub struct Pin<P> {
411411 // - deter downstream users from accessing it (which would be unsound!),
412412 // - let the `pin!` macro access it (such a macro requires using struct
413413 // literal syntax in order to benefit from lifetime extension).
414- // Long-term, `unsafe` fields or macro hygiene are expected to offer more robust alternatives.
414+ //
415+ // However, if `P::Deref` exposes a field with the same name as this field,
416+ // then the two will collide, resulting in a confusing error when the user
417+ // attempts to access the field through a `Pin<P>`. Therefore, the name
418+ // `__pointer` is designed to be unlikely to collide with any other
419+ // field. Long-term, macro hygiene is expected to offer a more robust
420+ // alternative, alongside `unsafe` fields.
415421 #[ unstable( feature = "unsafe_pin_internals" , issue = "none" ) ]
416422 #[ doc( hidden) ]
417- pub pointer : P ,
423+ pub __pointer : P ,
418424}
419425
420426// The following implementations aren't derived in order to avoid soundness
421- // issues. `&self.pointer ` should not be accessible to untrusted trait
427+ // issues. `&self.__pointer ` should not be accessible to untrusted trait
422428// implementations.
423429//
424430// See <https://internals.rust-lang.org/t/unsoundness-in-pin/11311/73> for more details.
@@ -525,7 +531,7 @@ impl<P: Deref<Target: Unpin>> Pin<P> {
525531 #[ rustc_const_unstable( feature = "const_pin" , issue = "76654" ) ]
526532 #[ stable( feature = "pin_into_inner" , since = "1.39.0" ) ]
527533 pub const fn into_inner ( pin : Pin < P > ) -> P {
528- pin. pointer
534+ pin. __pointer
529535 }
530536}
531537
@@ -654,7 +660,7 @@ impl<P: Deref> Pin<P> {
654660 #[ rustc_const_unstable( feature = "const_pin" , issue = "76654" ) ]
655661 #[ stable( feature = "pin" , since = "1.33.0" ) ]
656662 pub const unsafe fn new_unchecked ( pointer : P ) -> Pin < P > {
657- Pin { pointer }
663+ Pin { __pointer : pointer }
658664 }
659665
660666 /// Gets a pinned shared reference from this pinned pointer.
@@ -668,7 +674,7 @@ impl<P: Deref> Pin<P> {
668674 #[ inline( always) ]
669675 pub fn as_ref ( & self ) -> Pin < & P :: Target > {
670676 // SAFETY: see documentation on this function
671- unsafe { Pin :: new_unchecked ( & * self . pointer ) }
677+ unsafe { Pin :: new_unchecked ( & * self . __pointer ) }
672678 }
673679
674680 /// Unwraps this `Pin<P>` returning the underlying pointer.
@@ -688,7 +694,7 @@ impl<P: Deref> Pin<P> {
688694 #[ rustc_const_unstable( feature = "const_pin" , issue = "76654" ) ]
689695 #[ stable( feature = "pin_into_inner" , since = "1.39.0" ) ]
690696 pub const unsafe fn into_inner_unchecked ( pin : Pin < P > ) -> P {
691- pin. pointer
697+ pin. __pointer
692698 }
693699}
694700
@@ -725,7 +731,7 @@ impl<P: DerefMut> Pin<P> {
725731 #[ inline( always) ]
726732 pub fn as_mut ( & mut self ) -> Pin < & mut P :: Target > {
727733 // SAFETY: see documentation on this function
728- unsafe { Pin :: new_unchecked ( & mut * self . pointer ) }
734+ unsafe { Pin :: new_unchecked ( & mut * self . __pointer ) }
729735 }
730736
731737 /// Assigns a new value to the memory behind the pinned reference.
@@ -750,7 +756,7 @@ impl<P: DerefMut> Pin<P> {
750756 where
751757 P :: Target : Sized ,
752758 {
753- * ( self . pointer ) = value;
759+ * ( self . __pointer ) = value;
754760 }
755761}
756762
@@ -776,7 +782,7 @@ impl<'a, T: ?Sized> Pin<&'a T> {
776782 U : ?Sized ,
777783 F : FnOnce ( & T ) -> & U ,
778784 {
779- let pointer = & * self . pointer ;
785+ let pointer = & * self . __pointer ;
780786 let new_pointer = func ( pointer) ;
781787
782788 // SAFETY: the safety contract for `new_unchecked` must be
@@ -806,7 +812,7 @@ impl<'a, T: ?Sized> Pin<&'a T> {
806812 #[ rustc_const_unstable( feature = "const_pin" , issue = "76654" ) ]
807813 #[ stable( feature = "pin" , since = "1.33.0" ) ]
808814 pub const fn get_ref ( self ) -> & ' a T {
809- self . pointer
815+ self . __pointer
810816 }
811817}
812818
@@ -817,7 +823,7 @@ impl<'a, T: ?Sized> Pin<&'a mut T> {
817823 #[ rustc_const_unstable( feature = "const_pin" , issue = "76654" ) ]
818824 #[ stable( feature = "pin" , since = "1.33.0" ) ]
819825 pub const fn into_ref ( self ) -> Pin < & ' a T > {
820- Pin { pointer : self . pointer }
826+ Pin { __pointer : self . __pointer }
821827 }
822828
823829 /// Gets a mutable reference to the data inside of this `Pin`.
@@ -837,7 +843,7 @@ impl<'a, T: ?Sized> Pin<&'a mut T> {
837843 where
838844 T : Unpin ,
839845 {
840- self . pointer
846+ self . __pointer
841847 }
842848
843849 /// Gets a mutable reference to the data inside of this `Pin`.
@@ -855,7 +861,7 @@ impl<'a, T: ?Sized> Pin<&'a mut T> {
855861 #[ stable( feature = "pin" , since = "1.33.0" ) ]
856862 #[ rustc_const_unstable( feature = "const_pin" , issue = "76654" ) ]
857863 pub const unsafe fn get_unchecked_mut ( self ) -> & ' a mut T {
858- self . pointer
864+ self . __pointer
859865 }
860866
861867 /// Construct a new pin by mapping the interior value.
@@ -978,21 +984,21 @@ impl<P: Receiver> Receiver for Pin<P> {}
978984#[ stable( feature = "pin" , since = "1.33.0" ) ]
979985impl < P : fmt:: Debug > fmt:: Debug for Pin < P > {
980986 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
981- fmt:: Debug :: fmt ( & self . pointer , f)
987+ fmt:: Debug :: fmt ( & self . __pointer , f)
982988 }
983989}
984990
985991#[ stable( feature = "pin" , since = "1.33.0" ) ]
986992impl < P : fmt:: Display > fmt:: Display for Pin < P > {
987993 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
988- fmt:: Display :: fmt ( & self . pointer , f)
994+ fmt:: Display :: fmt ( & self . __pointer , f)
989995 }
990996}
991997
992998#[ stable( feature = "pin" , since = "1.33.0" ) ]
993999impl < P : fmt:: Pointer > fmt:: Pointer for Pin < P > {
9941000 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
995- fmt:: Pointer :: fmt ( & self . pointer , f)
1001+ fmt:: Pointer :: fmt ( & self . __pointer , f)
9961002 }
9971003}
9981004
@@ -1235,16 +1241,16 @@ pub macro pin($value:expr $(,)?) {
12351241 // instead, dropped _at the end of the enscoping block_.
12361242 // For instance,
12371243 // ```rust
1238- // let p = Pin { pointer : &mut <temporary> };
1244+ // let p = Pin { __pointer : &mut <temporary> };
12391245 // ```
12401246 // becomes:
12411247 // ```rust
12421248 // let mut anon = <temporary>;
1243- // let p = Pin { pointer : &mut anon };
1249+ // let p = Pin { __pointer : &mut anon };
12441250 // ```
12451251 // which is *exactly* what we want.
12461252 //
12471253 // See https://doc.rust-lang.org/1.58.1/reference/destructors.html#temporary-lifetime-extension
12481254 // for more info.
1249- $crate:: pin:: Pin :: < & mut _ > { pointer : & mut { $value } }
1255+ $crate:: pin:: Pin :: < & mut _ > { __pointer : & mut { $value } }
12501256}
0 commit comments