@@ -1092,14 +1092,20 @@ pub struct Pin<Ptr> {
1092
1092
// - deter downstream users from accessing it (which would be unsound!),
1093
1093
// - let the `pin!` macro access it (such a macro requires using struct
1094
1094
// 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.
1096
1102
#[ unstable( feature = "unsafe_pin_internals" , issue = "none" ) ]
1097
1103
#[ doc( hidden) ]
1098
- pub pointer : Ptr ,
1104
+ pub __pointer : Ptr ,
1099
1105
}
1100
1106
1101
1107
// 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
1103
1109
// implementations.
1104
1110
//
1105
1111
// 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> {
1212
1218
#[ rustc_const_unstable( feature = "const_pin" , issue = "76654" ) ]
1213
1219
#[ stable( feature = "pin_into_inner" , since = "1.39.0" ) ]
1214
1220
pub const fn into_inner ( pin : Pin < Ptr > ) -> Ptr {
1215
- pin. pointer
1221
+ pin. __pointer
1216
1222
}
1217
1223
}
1218
1224
@@ -1349,7 +1355,7 @@ impl<Ptr: Deref> Pin<Ptr> {
1349
1355
#[ rustc_const_unstable( feature = "const_pin" , issue = "76654" ) ]
1350
1356
#[ stable( feature = "pin" , since = "1.33.0" ) ]
1351
1357
pub const unsafe fn new_unchecked ( pointer : Ptr ) -> Pin < Ptr > {
1352
- Pin { pointer }
1358
+ Pin { __pointer : pointer }
1353
1359
}
1354
1360
1355
1361
/// Gets a shared reference to the pinned value this [`Pin`] points to.
@@ -1363,7 +1369,7 @@ impl<Ptr: Deref> Pin<Ptr> {
1363
1369
#[ inline( always) ]
1364
1370
pub fn as_ref ( & self ) -> Pin < & Ptr :: Target > {
1365
1371
// SAFETY: see documentation on this function
1366
- unsafe { Pin :: new_unchecked ( & * self . pointer ) }
1372
+ unsafe { Pin :: new_unchecked ( & * self . __pointer ) }
1367
1373
}
1368
1374
1369
1375
/// Unwraps this `Pin<Ptr>`, returning the underlying `Ptr`.
@@ -1388,7 +1394,7 @@ impl<Ptr: Deref> Pin<Ptr> {
1388
1394
#[ rustc_const_unstable( feature = "const_pin" , issue = "76654" ) ]
1389
1395
#[ stable( feature = "pin_into_inner" , since = "1.39.0" ) ]
1390
1396
pub const unsafe fn into_inner_unchecked ( pin : Pin < Ptr > ) -> Ptr {
1391
- pin. pointer
1397
+ pin. __pointer
1392
1398
}
1393
1399
}
1394
1400
@@ -1426,7 +1432,7 @@ impl<Ptr: DerefMut> Pin<Ptr> {
1426
1432
#[ inline( always) ]
1427
1433
pub fn as_mut ( & mut self ) -> Pin < & mut Ptr :: Target > {
1428
1434
// SAFETY: see documentation on this function
1429
- unsafe { Pin :: new_unchecked ( & mut * self . pointer ) }
1435
+ unsafe { Pin :: new_unchecked ( & mut * self . __pointer ) }
1430
1436
}
1431
1437
1432
1438
/// Assigns a new value to the memory location pointed to by the `Pin<Ptr>`.
@@ -1455,7 +1461,7 @@ impl<Ptr: DerefMut> Pin<Ptr> {
1455
1461
where
1456
1462
Ptr :: Target : Sized ,
1457
1463
{
1458
- * ( self . pointer ) = value;
1464
+ * ( self . __pointer ) = value;
1459
1465
}
1460
1466
}
1461
1467
@@ -1481,7 +1487,7 @@ impl<'a, T: ?Sized> Pin<&'a T> {
1481
1487
U : ?Sized ,
1482
1488
F : FnOnce ( & T ) -> & U ,
1483
1489
{
1484
- let pointer = & * self . pointer ;
1490
+ let pointer = & * self . __pointer ;
1485
1491
let new_pointer = func ( pointer) ;
1486
1492
1487
1493
// SAFETY: the safety contract for `new_unchecked` must be
@@ -1511,7 +1517,7 @@ impl<'a, T: ?Sized> Pin<&'a T> {
1511
1517
#[ rustc_const_unstable( feature = "const_pin" , issue = "76654" ) ]
1512
1518
#[ stable( feature = "pin" , since = "1.33.0" ) ]
1513
1519
pub const fn get_ref ( self ) -> & ' a T {
1514
- self . pointer
1520
+ self . __pointer
1515
1521
}
1516
1522
}
1517
1523
@@ -1522,7 +1528,7 @@ impl<'a, T: ?Sized> Pin<&'a mut T> {
1522
1528
#[ rustc_const_unstable( feature = "const_pin" , issue = "76654" ) ]
1523
1529
#[ stable( feature = "pin" , since = "1.33.0" ) ]
1524
1530
pub const fn into_ref ( self ) -> Pin < & ' a T > {
1525
- Pin { pointer : self . pointer }
1531
+ Pin { __pointer : self . __pointer }
1526
1532
}
1527
1533
1528
1534
/// Gets a mutable reference to the data inside of this `Pin`.
@@ -1542,7 +1548,7 @@ impl<'a, T: ?Sized> Pin<&'a mut T> {
1542
1548
where
1543
1549
T : Unpin ,
1544
1550
{
1545
- self . pointer
1551
+ self . __pointer
1546
1552
}
1547
1553
1548
1554
/// Gets a mutable reference to the data inside of this `Pin`.
@@ -1560,7 +1566,7 @@ impl<'a, T: ?Sized> Pin<&'a mut T> {
1560
1566
#[ stable( feature = "pin" , since = "1.33.0" ) ]
1561
1567
#[ rustc_const_unstable( feature = "const_pin" , issue = "76654" ) ]
1562
1568
pub const unsafe fn get_unchecked_mut ( self ) -> & ' a mut T {
1563
- self . pointer
1569
+ self . __pointer
1564
1570
}
1565
1571
1566
1572
/// Construct a new pin by mapping the interior value.
@@ -1684,21 +1690,21 @@ impl<Ptr: Receiver> Receiver for Pin<Ptr> {}
1684
1690
#[ stable( feature = "pin" , since = "1.33.0" ) ]
1685
1691
impl < Ptr : fmt:: Debug > fmt:: Debug for Pin < Ptr > {
1686
1692
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1687
- fmt:: Debug :: fmt ( & self . pointer , f)
1693
+ fmt:: Debug :: fmt ( & self . __pointer , f)
1688
1694
}
1689
1695
}
1690
1696
1691
1697
#[ stable( feature = "pin" , since = "1.33.0" ) ]
1692
1698
impl < Ptr : fmt:: Display > fmt:: Display for Pin < Ptr > {
1693
1699
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1694
- fmt:: Display :: fmt ( & self . pointer , f)
1700
+ fmt:: Display :: fmt ( & self . __pointer , f)
1695
1701
}
1696
1702
}
1697
1703
1698
1704
#[ stable( feature = "pin" , since = "1.33.0" ) ]
1699
1705
impl < Ptr : fmt:: Pointer > fmt:: Pointer for Pin < Ptr > {
1700
1706
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1701
- fmt:: Pointer :: fmt ( & self . pointer , f)
1707
+ fmt:: Pointer :: fmt ( & self . __pointer , f)
1702
1708
}
1703
1709
}
1704
1710
@@ -1941,16 +1947,16 @@ pub macro pin($value:expr $(,)?) {
1941
1947
// instead, dropped _at the end of the enscoping block_.
1942
1948
// For instance,
1943
1949
// ```rust
1944
- // let p = Pin { pointer : &mut <temporary> };
1950
+ // let p = Pin { __pointer : &mut <temporary> };
1945
1951
// ```
1946
1952
// becomes:
1947
1953
// ```rust
1948
1954
// let mut anon = <temporary>;
1949
- // let p = Pin { pointer : &mut anon };
1955
+ // let p = Pin { __pointer : &mut anon };
1950
1956
// ```
1951
1957
// which is *exactly* what we want.
1952
1958
//
1953
1959
// See https://doc.rust-lang.org/1.58.1/reference/destructors.html#temporary-lifetime-extension
1954
1960
// for more info.
1955
- $crate:: pin:: Pin :: < & mut _ > { pointer : & mut { $value } }
1961
+ $crate:: pin:: Pin :: < & mut _ > { __pointer : & mut { $value } }
1956
1962
}
0 commit comments