Skip to content

Commit 08b80e9

Browse files
committed
core: make pointer field of Pin private
As the fix-me comment suggested, use the macro hygiene of macros 2.0 to access the field in the `pin` macro. Therefore, the field can be made private.
1 parent 090d5ea commit 08b80e9

File tree

3 files changed

+7
-18
lines changed

3 files changed

+7
-18
lines changed

library/core/src/pin.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -407,14 +407,7 @@ use crate::ops::{CoerceUnsized, Deref, DerefMut, DispatchFromDyn, Receiver};
407407
#[repr(transparent)]
408408
#[derive(Copy, Clone)]
409409
pub struct Pin<P> {
410-
// FIXME(#93176): this field is made `#[unstable] #[doc(hidden)] pub` to:
411-
// - deter downstream users from accessing it (which would be unsound!),
412-
// - let the `pin!` macro access it (such a macro requires using struct
413-
// literal syntax in order to benefit from lifetime extension).
414-
// Long-term, `unsafe` fields or macro hygiene are expected to offer more robust alternatives.
415-
#[unstable(feature = "unsafe_pin_internals", issue = "none")]
416-
#[doc(hidden)]
417-
pub pointer: P,
410+
pointer: P,
418411
}
419412

420413
// The following implementations aren't derived in order to avoid soundness
@@ -1173,8 +1166,6 @@ impl<P, U> DispatchFromDyn<Pin<U>> for Pin<P> where P: DispatchFromDyn<U> {}
11731166
///
11741167
/// [`Box::pin`]: ../../std/boxed/struct.Box.html#method.pin
11751168
#[stable(feature = "pin_macro", since = "1.68.0")]
1176-
#[rustc_macro_transparency = "semitransparent"]
1177-
#[allow_internal_unstable(unsafe_pin_internals)]
11781169
pub macro pin($value:expr $(,)?) {
11791170
// This is `Pin::new_unchecked(&mut { $value })`, so, for starters, let's
11801171
// review such a hypothetical macro (that any user-code could define):
@@ -1246,5 +1237,5 @@ pub macro pin($value:expr $(,)?) {
12461237
//
12471238
// See https://doc.rust-lang.org/1.58.1/reference/destructors.html#temporary-lifetime-extension
12481239
// for more info.
1249-
$crate::pin::Pin::<&mut _> { pointer: &mut { $value } }
1240+
Pin { pointer: &mut { $value } }
12501241
}

tests/ui/pin-macro/cant_access_internals.rs

Lines changed: 1 addition & 1 deletion
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 field `pointer` of struct `Pin` is private
1212
}
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
error[E0658]: use of unstable library feature 'unsafe_pin_internals'
2-
--> $DIR/cant_access_internals.rs:11:15
1+
error[E0616]: field `pointer` of struct `Pin` is private
2+
--> $DIR/cant_access_internals.rs:11:30
33
|
44
LL | mem::take(phantom_pinned.pointer);
5-
| ^^^^^^^^^^^^^^^^^^^^^^
6-
|
7-
= help: add `#![feature(unsafe_pin_internals)]` to the crate attributes to enable
5+
| ^^^^^^^ private field
86

97
error: aborting due to 1 previous error
108

11-
For more information about this error, try `rustc --explain E0658`.
9+
For more information about this error, try `rustc --explain E0616`.

0 commit comments

Comments
 (0)