diff options
| author | Henri Sivonen <hsivonen@hsivonen.fi> | 2017-04-28 12:25:02 +0300 |
|---|---|---|
| committer | Henri Sivonen <hsivonen@hsivonen.fi> | 2017-04-28 12:25:02 +0300 |
| commit | e36f59e1a2a5d94512b5fb66a0e4e224cd15c092 (patch) | |
| tree | 74683f5bdc704b425593c926da47a908f43f484f /src/libcore/slice | |
| parent | ace517da0d1e356aa5b42f4cdee6854538591ef2 (diff) | |
| download | rust-e36f59e1a2a5d94512b5fb66a0e4e224cd15c092.tar.gz rust-e36f59e1a2a5d94512b5fb66a0e4e224cd15c092.zip | |
Explain why zero-length slices require a non-null pointer
Diffstat (limited to 'src/libcore/slice')
| -rw-r--r-- | src/libcore/slice/mod.rs | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index 87dfdfe57b6..9e3bd911546 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -2354,7 +2354,10 @@ impl<'a, T> FusedIterator for ChunksMut<'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. +/// `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. /// /// # Caveat /// @@ -2387,7 +2390,8 @@ pub unsafe fn from_raw_parts<'a, T>(p: *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. +/// mutable slice. `p` must be non-null even for zero-length slices as with +/// `from_raw_parts`. #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub unsafe fn from_raw_parts_mut<'a, T>(p: *mut T, len: usize) -> &'a mut [T] { |
