about summary refs log tree commit diff
path: root/src/libcore/slice
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2018-05-28 18:27:26 +0200
committerRalf Jung <post@ralfj.de>2018-05-28 18:34:15 +0200
commit3ee9d899695edf3a00870f6243c27c21d9084a8f (patch)
treeccda38a4ee1f6e6726112b3c26e284e5629814cc /src/libcore/slice
parent2b1d69d6b520046108dae04c625f15ea35127388 (diff)
downloadrust-3ee9d899695edf3a00870f6243c27c21d9084a8f.tar.gz
rust-3ee9d899695edf3a00870f6243c27c21d9084a8f.zip
extend from_raw_parts docs for slices and strs to mention alignment requirement
Diffstat (limited to 'src/libcore/slice')
-rw-r--r--src/libcore/slice/mod.rs11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs
index ab986e4c86d..d52cc8cbe3f 100644
--- a/src/libcore/slice/mod.rs
+++ b/src/libcore/slice/mod.rs
@@ -3839,10 +3839,9 @@ unsafe impl<'a, T> TrustedRandomAccess for ExactChunksMut<'a, T> {
 /// valid for `len` elements, nor whether the lifetime inferred is a suitable
 /// lifetime for the returned slice.
 ///
-/// `p` must be non-null, even for zero-length slices, because non-zero bits
-/// are required to distinguish between a zero-length slice within `Some()`
-/// from `None`. `p` can be a bogus non-dereferencable pointer, such as `0x1`,
-/// for zero-length slices, though.
+/// `p` must be non-null and aligned, even for zero-length slices, as is
+/// required for all references. However, for zero-length slices, `p` can be
+/// a bogus non-dereferencable pointer such as [`NonNull::dangling()`].
 ///
 /// # Caveat
 ///
@@ -3864,6 +3863,8 @@ unsafe impl<'a, T> TrustedRandomAccess for ExactChunksMut<'a, T> {
 ///     let slice = slice::from_raw_parts(ptr, amt);
 /// }
 /// ```
+///
+/// [`NonNull::dangling()`]: ../../std/ptr/struct.NonNull.html#method.dangling
 #[inline]
 #[stable(feature = "rust1", since = "1.0.0")]
 pub unsafe fn from_raw_parts<'a, T>(data: *const T, len: usize) -> &'a [T] {
@@ -3875,7 +3876,7 @@ pub unsafe fn from_raw_parts<'a, T>(data: *const T, len: usize) -> &'a [T] {
 ///
 /// This function is unsafe for the same reasons as `from_raw_parts`, as well
 /// as not being able to provide a non-aliasing guarantee of the returned
-/// mutable slice. `p` must be non-null even for zero-length slices as with
+/// mutable slice. `p` must be non-null and aligned even for zero-length slices as with
 /// `from_raw_parts`.
 #[inline]
 #[stable(feature = "rust1", since = "1.0.0")]