@@ -1074,17 +1074,22 @@ impl<T: ?Sized> *const T {
1074
1074
/// operation because the returned value could be pointing to invalid
1075
1075
/// memory.
1076
1076
///
1077
- /// When calling this method, you have to ensure that if the pointer is
1078
- /// non-NULL, then it is properly aligned, dereferencable (for the whole
1079
- /// size of `T`) and points to an initialized instance of `T`. This applies
1080
- /// even if the result of this method is unused!
1077
+ /// When calling this method, you have to ensure that *either* the pointer is NULL *or*
1078
+ /// all of the following is true:
1079
+ /// - it is properly aligned
1080
+ /// - it must point to an initialized instance of T; in particular, the pointer must be
1081
+ /// "dereferencable" in the sense defined [here].
1082
+ ///
1083
+ /// This applies even if the result of this method is unused!
1081
1084
/// (The part about being initialized is not yet fully decided, but until
1082
1085
/// it is, the only safe approach is to ensure that they are indeed initialized.)
1083
1086
///
1084
1087
/// Additionally, the lifetime `'a` returned is arbitrarily chosen and does
1085
- /// not necessarily reflect the actual lifetime of the data. It is up to the
1086
- /// caller to ensure that for the duration of this lifetime, the memory this
1087
- /// pointer points to does not get written to outside of `UnsafeCell<U>`.
1088
+ /// not necessarily reflect the actual lifetime of the data. *You* must enforce
1089
+ /// Rust's aliasing rules. In particular, for the duration of this lifetime,
1090
+ /// the memory the pointer points to must not get mutated (except inside `UnsafeCell`).
1091
+ ///
1092
+ /// [here]: crate::ptr#safety
1088
1093
///
1089
1094
/// # Examples
1090
1095
///
@@ -1929,18 +1934,23 @@ impl<T: ?Sized> *mut T {
1929
1934
/// of the returned pointer, nor can it ensure that the lifetime `'a`
1930
1935
/// returned is indeed a valid lifetime for the contained data.
1931
1936
///
1932
- /// When calling this method, you have to ensure that if the pointer is
1933
- /// non-NULL, then it is properly aligned, dereferencable (for the whole
1934
- /// size of `T`) and points to an initialized instance of `T`. This applies
1935
- /// even if the result of this method is unused!
1937
+ /// When calling this method, you have to ensure that *either* the pointer is NULL *or*
1938
+ /// all of the following is true:
1939
+ /// - it is properly aligned
1940
+ /// - it must point to an initialized instance of T; in particular, the pointer must be
1941
+ /// "dereferencable" in the sense defined [here].
1942
+ ///
1943
+ /// This applies even if the result of this method is unused!
1936
1944
/// (The part about being initialized is not yet fully decided, but until
1937
1945
/// it is the only safe approach is to ensure that they are indeed initialized.)
1938
1946
///
1939
1947
/// Additionally, the lifetime `'a` returned is arbitrarily chosen and does
1940
- /// not necessarily reflect the actual lifetime of the data. It is up to the
1941
- /// caller to ensure that for the duration of this lifetime, the memory this
1942
- /// pointer points to does not get accessed through any other pointer.
1948
+ /// not necessarily reflect the actual lifetime of the data. *You* must enforce
1949
+ /// Rust's aliasing rules. In particular, for the duration of this lifetime,
1950
+ /// the memory this pointer points to must not get accessed (read or written)
1951
+ /// through any other pointer.
1943
1952
///
1953
+ /// [here]: crate::ptr#safety
1944
1954
/// [`as_ref`]: #method.as_ref
1945
1955
///
1946
1956
/// # Examples
0 commit comments