Skip to content

Commit 40df8fd

Browse files
committed
Apply #66379 to *mut T as_ref
1 parent f9a3086 commit 40df8fd

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/libcore/ptr/mut_ptr.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,22 @@ impl<T: ?Sized> *mut T {
4747
/// operation because the returned value could be pointing to invalid
4848
/// memory.
4949
///
50-
/// When calling this method, you have to ensure that if the pointer is
51-
/// non-NULL, then it is properly aligned, dereferenceable (for the whole
52-
/// size of `T`) and points to an initialized instance of `T`. This applies
53-
/// even if the result of this method is unused!
50+
/// When calling this method, you have to ensure that *either* the pointer is NULL *or*
51+
/// all of the following is true:
52+
/// - it is properly aligned
53+
/// - it must point to an initialized instance of T; in particular, the pointer must be
54+
/// "dereferencable" in the sense defined [here].
55+
///
56+
/// This applies even if the result of this method is unused!
5457
/// (The part about being initialized is not yet fully decided, but until
5558
/// it is, the only safe approach is to ensure that they are indeed initialized.)
5659
///
5760
/// Additionally, the lifetime `'a` returned is arbitrarily chosen and does
58-
/// not necessarily reflect the actual lifetime of the data. It is up to the
59-
/// caller to ensure that for the duration of this lifetime, the memory this
60-
/// pointer points to does not get written to outside of `UnsafeCell<U>`.
61+
/// not necessarily reflect the actual lifetime of the data. *You* must enforce
62+
/// Rust's aliasing rules. In particular, for the duration of this lifetime,
63+
/// the memory the pointer points to must not get mutated (except inside `UnsafeCell`).
64+
///
65+
/// [here]: crate::ptr#safety
6166
///
6267
/// # Examples
6368
///

0 commit comments

Comments
 (0)