@@ -86,11 +86,14 @@ impl<T: ?Sized> UnsafePinned<T> {
8686 ptr:: from_mut ( self ) as * mut T
8787 }
8888
89- /// Get read-only access to the contents of a shared `UnsafePinned`.
89+ /// Get mutable access to the contents of a shared `UnsafePinned`.
9090 ///
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`].
9497 ///
9598 /// [`UnsafeCell`]: crate::cell::UnsafeCell
9699 ///
@@ -100,16 +103,16 @@ impl<T: ?Sized> UnsafePinned<T> {
100103 ///
101104 /// unsafe {
102105 /// let mut x = UnsafePinned::new(0);
103- /// let ptr = x.get(); // read-only pointer, assumes immutability
106+ /// let ptr = x.get();
104107 /// x.get_mut_unchecked().write(1);
105- /// ptr.read(); // UB!
108+ /// assert_eq!( ptr.read(), 1);
106109 /// }
107110 /// ```
108111 #[ inline( always) ]
109112 #[ must_use]
110113 #[ 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 ( )
113116 }
114117
115118 /// Gets an immutable pointer to the wrapped value.
0 commit comments