Skip to content

Commit 0750d0d

Browse files
Rename pointer field on Pin
The internal, unstable field of `Pin` can conflict with fields from the inner type accessed via the `Deref` impl. Rename it from `pointer` to `__pointer`, to make it less likely to conflict with anything else.
1 parent 139fb22 commit 0750d0d

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

library/core/src/pin.rs

+19-19
Original file line numberDiff line numberDiff line change
@@ -414,11 +414,11 @@ pub struct Pin<P> {
414414
// Long-term, `unsafe` fields or macro hygiene are expected to offer more robust alternatives.
415415
#[unstable(feature = "unsafe_pin_internals", issue = "none")]
416416
#[doc(hidden)]
417-
pub pointer: P,
417+
pub __pointer: P,
418418
}
419419

420420
// The following implementations aren't derived in order to avoid soundness
421-
// issues. `&self.pointer` should not be accessible to untrusted trait
421+
// issues. `&self.__pointer` should not be accessible to untrusted trait
422422
// implementations.
423423
//
424424
// See <https://internals.rust-lang.org/t/unsoundness-in-pin/11311/73> for more details.
@@ -525,7 +525,7 @@ impl<P: Deref<Target: Unpin>> Pin<P> {
525525
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
526526
#[stable(feature = "pin_into_inner", since = "1.39.0")]
527527
pub const fn into_inner(pin: Pin<P>) -> P {
528-
pin.pointer
528+
pin.__pointer
529529
}
530530
}
531531

@@ -654,7 +654,7 @@ impl<P: Deref> Pin<P> {
654654
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
655655
#[stable(feature = "pin", since = "1.33.0")]
656656
pub const unsafe fn new_unchecked(pointer: P) -> Pin<P> {
657-
Pin { pointer }
657+
Pin { __pointer: pointer }
658658
}
659659

660660
/// Gets a pinned shared reference from this pinned pointer.
@@ -668,7 +668,7 @@ impl<P: Deref> Pin<P> {
668668
#[inline(always)]
669669
pub fn as_ref(&self) -> Pin<&P::Target> {
670670
// SAFETY: see documentation on this function
671-
unsafe { Pin::new_unchecked(&*self.pointer) }
671+
unsafe { Pin::new_unchecked(&*self.__pointer) }
672672
}
673673

674674
/// Unwraps this `Pin<P>` returning the underlying pointer.
@@ -688,7 +688,7 @@ impl<P: Deref> Pin<P> {
688688
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
689689
#[stable(feature = "pin_into_inner", since = "1.39.0")]
690690
pub const unsafe fn into_inner_unchecked(pin: Pin<P>) -> P {
691-
pin.pointer
691+
pin.__pointer
692692
}
693693
}
694694

@@ -725,7 +725,7 @@ impl<P: DerefMut> Pin<P> {
725725
#[inline(always)]
726726
pub fn as_mut(&mut self) -> Pin<&mut P::Target> {
727727
// SAFETY: see documentation on this function
728-
unsafe { Pin::new_unchecked(&mut *self.pointer) }
728+
unsafe { Pin::new_unchecked(&mut *self.__pointer) }
729729
}
730730

731731
/// Assigns a new value to the memory behind the pinned reference.
@@ -750,7 +750,7 @@ impl<P: DerefMut> Pin<P> {
750750
where
751751
P::Target: Sized,
752752
{
753-
*(self.pointer) = value;
753+
*(self.__pointer) = value;
754754
}
755755
}
756756

@@ -776,7 +776,7 @@ impl<'a, T: ?Sized> Pin<&'a T> {
776776
U: ?Sized,
777777
F: FnOnce(&T) -> &U,
778778
{
779-
let pointer = &*self.pointer;
779+
let pointer = &*self.__pointer;
780780
let new_pointer = func(pointer);
781781

782782
// SAFETY: the safety contract for `new_unchecked` must be
@@ -806,7 +806,7 @@ impl<'a, T: ?Sized> Pin<&'a T> {
806806
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
807807
#[stable(feature = "pin", since = "1.33.0")]
808808
pub const fn get_ref(self) -> &'a T {
809-
self.pointer
809+
self.__pointer
810810
}
811811
}
812812

@@ -817,7 +817,7 @@ impl<'a, T: ?Sized> Pin<&'a mut T> {
817817
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
818818
#[stable(feature = "pin", since = "1.33.0")]
819819
pub const fn into_ref(self) -> Pin<&'a T> {
820-
Pin { pointer: self.pointer }
820+
Pin { __pointer: self.__pointer }
821821
}
822822

823823
/// Gets a mutable reference to the data inside of this `Pin`.
@@ -837,7 +837,7 @@ impl<'a, T: ?Sized> Pin<&'a mut T> {
837837
where
838838
T: Unpin,
839839
{
840-
self.pointer
840+
self.__pointer
841841
}
842842

843843
/// Gets a mutable reference to the data inside of this `Pin`.
@@ -855,7 +855,7 @@ impl<'a, T: ?Sized> Pin<&'a mut T> {
855855
#[stable(feature = "pin", since = "1.33.0")]
856856
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
857857
pub const unsafe fn get_unchecked_mut(self) -> &'a mut T {
858-
self.pointer
858+
self.__pointer
859859
}
860860

861861
/// Construct a new pin by mapping the interior value.
@@ -978,21 +978,21 @@ impl<P: Receiver> Receiver for Pin<P> {}
978978
#[stable(feature = "pin", since = "1.33.0")]
979979
impl<P: fmt::Debug> fmt::Debug for Pin<P> {
980980
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
981-
fmt::Debug::fmt(&self.pointer, f)
981+
fmt::Debug::fmt(&self.__pointer, f)
982982
}
983983
}
984984

985985
#[stable(feature = "pin", since = "1.33.0")]
986986
impl<P: fmt::Display> fmt::Display for Pin<P> {
987987
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
988-
fmt::Display::fmt(&self.pointer, f)
988+
fmt::Display::fmt(&self.__pointer, f)
989989
}
990990
}
991991

992992
#[stable(feature = "pin", since = "1.33.0")]
993993
impl<P: fmt::Pointer> fmt::Pointer for Pin<P> {
994994
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
995-
fmt::Pointer::fmt(&self.pointer, f)
995+
fmt::Pointer::fmt(&self.__pointer, f)
996996
}
997997
}
998998

@@ -1235,16 +1235,16 @@ pub macro pin($value:expr $(,)?) {
12351235
// instead, dropped _at the end of the enscoping block_.
12361236
// For instance,
12371237
// ```rust
1238-
// let p = Pin { pointer: &mut <temporary> };
1238+
// let p = Pin { __pointer: &mut <temporary> };
12391239
// ```
12401240
// becomes:
12411241
// ```rust
12421242
// let mut anon = <temporary>;
1243-
// let p = Pin { pointer: &mut anon };
1243+
// let p = Pin { __pointer: &mut anon };
12441244
// ```
12451245
// which is *exactly* what we want.
12461246
//
12471247
// See https://doc.rust-lang.org/1.58.1/reference/destructors.html#temporary-lifetime-extension
12481248
// for more info.
1249-
$crate::pin::Pin::<&mut _> { pointer: &mut { $value } }
1249+
$crate::pin::Pin::<&mut _> { __pointer: &mut { $value } }
12501250
}

tests/ui/pin-macro/cant_access_internals.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ use core::{
88

99
fn main() {
1010
let mut phantom_pinned = pin!(PhantomPinned);
11-
mem::take(phantom_pinned.pointer); //~ ERROR use of unstable library feature 'unsafe_pin_internals'
11+
mem::take(phantom_pinned.__pointer); //~ ERROR use of unstable library feature 'unsafe_pin_internals'
1212
}

tests/ui/pin-macro/cant_access_internals.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0658]: use of unstable library feature 'unsafe_pin_internals'
22
--> $DIR/cant_access_internals.rs:11:15
33
|
4-
LL | mem::take(phantom_pinned.pointer);
5-
| ^^^^^^^^^^^^^^^^^^^^^^
4+
LL | mem::take(phantom_pinned.__pointer);
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= help: add `#![feature(unsafe_pin_internals)]` to the crate attributes to enable
88

0 commit comments

Comments
 (0)