@@ -192,13 +192,17 @@ Similarly, the intrusive linked list from the motivation can be fixed by wrappin
192
192
/// The type `UnsafePinned<T>` lets unsafe code violate
193
193
/// the rule that `&mut UnsafePinned<T>` may never alias anything else.
194
194
///
195
- /// However, it is still very risky to have an `&mut UnsafePinned<T>` that aliases
195
+ /// However, even if you define your type like `pub struct Wrapper(UnsafePinned<...>)`,
196
+ /// it is still very risky to have an `&mut Wrapper` that aliases
196
197
/// anything else. Many functions that work generically on `&mut T` assume that the
197
198
/// memory that stores `T` is uniquely owned (such as `mem::swap`). In other words,
198
- /// while having aliasing with `&mut UnsafePinned<T> ` is not immediate Undefined
199
+ /// while having aliasing with `&mut Wrapper ` is not immediate Undefined
199
200
/// Behavior, it is still unsound to expose such a mutable reference to code you do
200
- /// not control!
201
- /// Techniques such as pinning via `Pin` are needed to ensure soundness.
201
+ /// not control! Techniques such as pinning via `Pin` are needed to ensure soundness.
202
+ ///
203
+ /// Similar to `UnsafeCell`, `UnsafePinned` will not usually show up in the public
204
+ /// API of a library. It is an internal implementation detail of libraries that
205
+ /// need to support aliasing mutable references.
202
206
///
203
207
/// Further note that this does *not* lift the requirement that shared references
204
208
/// must be read-only! Use `UnsafeCell` for that.
@@ -227,10 +231,8 @@ impl<T: ?Sized> UnsafePinned<T> {
227
231
228
232
/// Get read-write access to the contents of an `UnsafePinned`.
229
233
///
230
- /// If you need to use this function, something is likely going wrong.
231
- /// Exposing an `&mut UnsafePinned` that aliases other pointers to code outside your
232
- /// crate is unsound. Only `Pin<&mut UnsafePinned>` can be exposed soundly.
233
- /// Use `get_mut_pinned` instead whenever possible!
234
+ /// You should usually be using `get_mut_pinned` instead to explicitly track
235
+ /// the fact that this memory is "pinned" due to there being aliases.
234
236
pub fn get_mut_unchecked (& mut self ) -> * mut T {
235
237
ptr :: addr_of_mut! (self . value)
236
238
}
0 commit comments