about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authoraticu <15schnic@gmail.com>2020-07-20 20:39:17 +0200
committeraticu <15schnic@gmail.com>2020-07-20 20:39:17 +0200
commit40df8fd0fad99db880bee40fce7c855922e7f0f9 (patch)
tree2e3465255950a39c10797c95f842d53a933a23fd /src/libcore
parentf9a3086363f214f2b56bef30f0ac572e1a9127f1 (diff)
downloadrust-40df8fd0fad99db880bee40fce7c855922e7f0f9.tar.gz
rust-40df8fd0fad99db880bee40fce7c855922e7f0f9.zip
Apply #66379 to `*mut T` `as_ref`
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/ptr/mut_ptr.rs19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/libcore/ptr/mut_ptr.rs b/src/libcore/ptr/mut_ptr.rs
index 96856e7512c..915dc3e45f6 100644
--- a/src/libcore/ptr/mut_ptr.rs
+++ b/src/libcore/ptr/mut_ptr.rs
@@ -47,17 +47,22 @@ impl<T: ?Sized> *mut T {
     /// operation because the returned value could be pointing to invalid
     /// memory.
     ///
-    /// When calling this method, you have to ensure that if the pointer is
-    /// non-NULL, then it is properly aligned, dereferenceable (for the whole
-    /// size of `T`) and points to an initialized instance of `T`. This applies
-    /// even if the result of this method is unused!
+    /// When calling this method, you have to ensure that *either* the pointer is NULL *or*
+    /// all of the following is true:
+    /// - it is properly aligned
+    /// - it must point to an initialized instance of T; in particular, the pointer must be
+    ///   "dereferencable" in the sense defined [here].
+    ///
+    /// This applies even if the result of this method is unused!
     /// (The part about being initialized is not yet fully decided, but until
     /// it is, the only safe approach is to ensure that they are indeed initialized.)
     ///
     /// Additionally, the lifetime `'a` returned is arbitrarily chosen and does
-    /// not necessarily reflect the actual lifetime of the data. It is up to the
-    /// caller to ensure that for the duration of this lifetime, the memory this
-    /// pointer points to does not get written to outside of `UnsafeCell<U>`.
+    /// not necessarily reflect the actual lifetime of the data. *You* must enforce
+    /// Rust's aliasing rules. In particular, for the duration of this lifetime,
+    /// the memory the pointer points to must not get mutated (except inside `UnsafeCell`).
+    ///
+    /// [here]: crate::ptr#safety
     ///
     /// # Examples
     ///