@@ -1092,14 +1092,20 @@ pub struct Pin<Ptr> {
10921092 // - deter downstream users from accessing it (which would be unsound!),
10931093 // - let the `pin!` macro access it (such a macro requires using struct
10941094 // literal syntax in order to benefit from lifetime extension).
1095- // Long-term, `unsafe` fields or macro hygiene are expected to offer more robust alternatives.
1095+ //
1096+ // However, if the `Deref` impl exposes a field with the same name as this
1097+ // field, then the two will collide, resulting in a confusing error when the
1098+ // user attempts to access the field through a `Pin<Ptr>`. Therefore, the
1099+ // name `__pointer` is designed to be unlikely to collide with any other
1100+ // field. Long-term, macro hygiene is expected to offer a more robust
1101+ // alternative, alongside `unsafe` fields.
10961102 #[ unstable( feature = "unsafe_pin_internals" , issue = "none" ) ]
10971103 #[ doc( hidden) ]
1098- pub pointer : Ptr ,
1104+ pub __pointer : Ptr ,
10991105}
11001106
11011107// The following implementations aren't derived in order to avoid soundness
1102- // issues. `&self.pointer ` should not be accessible to untrusted trait
1108+ // issues. `&self.__pointer ` should not be accessible to untrusted trait
11031109// implementations.
11041110//
11051111// See <https://internals.rust-lang.org/t/unsoundness-in-pin/11311/73> for more details.
@@ -1212,7 +1218,7 @@ impl<Ptr: Deref<Target: Unpin>> Pin<Ptr> {
12121218 #[ rustc_const_unstable( feature = "const_pin" , issue = "76654" ) ]
12131219 #[ stable( feature = "pin_into_inner" , since = "1.39.0" ) ]
12141220 pub const fn into_inner ( pin : Pin < Ptr > ) -> Ptr {
1215- pin. pointer
1221+ pin. __pointer
12161222 }
12171223}
12181224
@@ -1349,7 +1355,7 @@ impl<Ptr: Deref> Pin<Ptr> {
13491355 #[ rustc_const_unstable( feature = "const_pin" , issue = "76654" ) ]
13501356 #[ stable( feature = "pin" , since = "1.33.0" ) ]
13511357 pub const unsafe fn new_unchecked ( pointer : Ptr ) -> Pin < Ptr > {
1352- Pin { pointer }
1358+ Pin { __pointer : pointer }
13531359 }
13541360
13551361 /// Gets a shared reference to the pinned value this [`Pin`] points to.
@@ -1363,7 +1369,7 @@ impl<Ptr: Deref> Pin<Ptr> {
13631369 #[ inline( always) ]
13641370 pub fn as_ref ( & self ) -> Pin < & Ptr :: Target > {
13651371 // SAFETY: see documentation on this function
1366- unsafe { Pin :: new_unchecked ( & * self . pointer ) }
1372+ unsafe { Pin :: new_unchecked ( & * self . __pointer ) }
13671373 }
13681374
13691375 /// Unwraps this `Pin<Ptr>`, returning the underlying `Ptr`.
@@ -1388,7 +1394,7 @@ impl<Ptr: Deref> Pin<Ptr> {
13881394 #[ rustc_const_unstable( feature = "const_pin" , issue = "76654" ) ]
13891395 #[ stable( feature = "pin_into_inner" , since = "1.39.0" ) ]
13901396 pub const unsafe fn into_inner_unchecked ( pin : Pin < Ptr > ) -> Ptr {
1391- pin. pointer
1397+ pin. __pointer
13921398 }
13931399}
13941400
@@ -1426,7 +1432,7 @@ impl<Ptr: DerefMut> Pin<Ptr> {
14261432 #[ inline( always) ]
14271433 pub fn as_mut ( & mut self ) -> Pin < & mut Ptr :: Target > {
14281434 // SAFETY: see documentation on this function
1429- unsafe { Pin :: new_unchecked ( & mut * self . pointer ) }
1435+ unsafe { Pin :: new_unchecked ( & mut * self . __pointer ) }
14301436 }
14311437
14321438 /// Assigns a new value to the memory location pointed to by the `Pin<Ptr>`.
@@ -1455,7 +1461,7 @@ impl<Ptr: DerefMut> Pin<Ptr> {
14551461 where
14561462 Ptr :: Target : Sized ,
14571463 {
1458- * ( self . pointer ) = value;
1464+ * ( self . __pointer ) = value;
14591465 }
14601466}
14611467
@@ -1481,7 +1487,7 @@ impl<'a, T: ?Sized> Pin<&'a T> {
14811487 U : ?Sized ,
14821488 F : FnOnce ( & T ) -> & U ,
14831489 {
1484- let pointer = & * self . pointer ;
1490+ let pointer = & * self . __pointer ;
14851491 let new_pointer = func ( pointer) ;
14861492
14871493 // SAFETY: the safety contract for `new_unchecked` must be
@@ -1511,7 +1517,7 @@ impl<'a, T: ?Sized> Pin<&'a T> {
15111517 #[ rustc_const_unstable( feature = "const_pin" , issue = "76654" ) ]
15121518 #[ stable( feature = "pin" , since = "1.33.0" ) ]
15131519 pub const fn get_ref ( self ) -> & ' a T {
1514- self . pointer
1520+ self . __pointer
15151521 }
15161522}
15171523
@@ -1522,7 +1528,7 @@ impl<'a, T: ?Sized> Pin<&'a mut T> {
15221528 #[ rustc_const_unstable( feature = "const_pin" , issue = "76654" ) ]
15231529 #[ stable( feature = "pin" , since = "1.33.0" ) ]
15241530 pub const fn into_ref ( self ) -> Pin < & ' a T > {
1525- Pin { pointer : self . pointer }
1531+ Pin { __pointer : self . __pointer }
15261532 }
15271533
15281534 /// Gets a mutable reference to the data inside of this `Pin`.
@@ -1542,7 +1548,7 @@ impl<'a, T: ?Sized> Pin<&'a mut T> {
15421548 where
15431549 T : Unpin ,
15441550 {
1545- self . pointer
1551+ self . __pointer
15461552 }
15471553
15481554 /// Gets a mutable reference to the data inside of this `Pin`.
@@ -1560,7 +1566,7 @@ impl<'a, T: ?Sized> Pin<&'a mut T> {
15601566 #[ stable( feature = "pin" , since = "1.33.0" ) ]
15611567 #[ rustc_const_unstable( feature = "const_pin" , issue = "76654" ) ]
15621568 pub const unsafe fn get_unchecked_mut ( self ) -> & ' a mut T {
1563- self . pointer
1569+ self . __pointer
15641570 }
15651571
15661572 /// Construct a new pin by mapping the interior value.
@@ -1684,21 +1690,21 @@ impl<Ptr: Receiver> Receiver for Pin<Ptr> {}
16841690#[ stable( feature = "pin" , since = "1.33.0" ) ]
16851691impl < Ptr : fmt:: Debug > fmt:: Debug for Pin < Ptr > {
16861692 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1687- fmt:: Debug :: fmt ( & self . pointer , f)
1693+ fmt:: Debug :: fmt ( & self . __pointer , f)
16881694 }
16891695}
16901696
16911697#[ stable( feature = "pin" , since = "1.33.0" ) ]
16921698impl < Ptr : fmt:: Display > fmt:: Display for Pin < Ptr > {
16931699 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1694- fmt:: Display :: fmt ( & self . pointer , f)
1700+ fmt:: Display :: fmt ( & self . __pointer , f)
16951701 }
16961702}
16971703
16981704#[ stable( feature = "pin" , since = "1.33.0" ) ]
16991705impl < Ptr : fmt:: Pointer > fmt:: Pointer for Pin < Ptr > {
17001706 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1701- fmt:: Pointer :: fmt ( & self . pointer , f)
1707+ fmt:: Pointer :: fmt ( & self . __pointer , f)
17021708 }
17031709}
17041710
@@ -1941,16 +1947,16 @@ pub macro pin($value:expr $(,)?) {
19411947 // instead, dropped _at the end of the enscoping block_.
19421948 // For instance,
19431949 // ```rust
1944- // let p = Pin { pointer : &mut <temporary> };
1950+ // let p = Pin { __pointer : &mut <temporary> };
19451951 // ```
19461952 // becomes:
19471953 // ```rust
19481954 // let mut anon = <temporary>;
1949- // let p = Pin { pointer : &mut anon };
1955+ // let p = Pin { __pointer : &mut anon };
19501956 // ```
19511957 // which is *exactly* what we want.
19521958 //
19531959 // See https://doc.rust-lang.org/1.58.1/reference/destructors.html#temporary-lifetime-extension
19541960 // for more info.
1955- $crate:: pin:: Pin :: < & mut _ > { pointer : & mut { $value } }
1961+ $crate:: pin:: Pin :: < & mut _ > { __pointer : & mut { $value } }
19561962}
0 commit comments