@@ -86,11 +86,14 @@ impl<T: ?Sized> UnsafePinned<T> {
86
86
ptr:: from_mut ( self ) as * mut T
87
87
}
88
88
89
- /// Get read-only access to the contents of a shared `UnsafePinned`.
89
+ /// Get mutable access to the contents of a shared `UnsafePinned`.
90
90
///
91
- /// Note that `&UnsafePinned<T>` is read-only if `&T` is read-only. This means that if there is
92
- /// mutation of the `T`, future reads from the `*const T` returned here are UB! Use
93
- /// [`UnsafeCell`] if you also need interior mutability.
91
+ /// This can be cast to a pointer of any kind.
92
+ /// Ensure that the access is unique (no active references, mutable or not)
93
+ /// when casting to `&mut T`, and ensure that there are no mutations
94
+ /// or mutable aliases going on when casting to `&T`.
95
+ ///
96
+ /// All the usual caveats around mutation shared state apply, see [`UnsafeCell`].
94
97
///
95
98
/// [`UnsafeCell`]: crate::cell::UnsafeCell
96
99
///
@@ -100,16 +103,16 @@ impl<T: ?Sized> UnsafePinned<T> {
100
103
///
101
104
/// unsafe {
102
105
/// let mut x = UnsafePinned::new(0);
103
- /// let ptr = x.get(); // read-only pointer, assumes immutability
106
+ /// let ptr = x.get();
104
107
/// x.get_mut_unchecked().write(1);
105
- /// ptr.read(); // UB!
108
+ /// assert_eq!( ptr.read(), 1);
106
109
/// }
107
110
/// ```
108
111
#[ inline( always) ]
109
112
#[ must_use]
110
113
#[ unstable( feature = "unsafe_pinned" , issue = "125735" ) ]
111
- pub const fn get ( & self ) -> * const T {
112
- ptr :: from_ref ( self ) as * const T
114
+ pub const fn get ( & self ) -> * mut T {
115
+ self . value . get ( )
113
116
}
114
117
115
118
/// Gets an immutable pointer to the wrapped value.
0 commit comments