@@ -5,24 +5,7 @@ use crate::mem::{self, SizedTypeProperties};
5
5
use crate :: slice:: { self , SliceIndex } ;
6
6
7
7
impl < T : ?Sized > * mut T {
8
- /// Returns `true` if the pointer is null.
9
- ///
10
- /// Note that unsized types have many possible null pointers, as only the
11
- /// raw data pointer is considered, not their length, vtable, etc.
12
- /// Therefore, two pointers that are null may still not compare equal to
13
- /// each other.
14
- ///
15
- /// # Panics during const evaluation
16
- ///
17
- /// If this method is used during const evaluation, and `self` is a pointer
18
- /// that is offset beyond the bounds of the memory it initially pointed to,
19
- /// then there might not be enough information to determine whether the
20
- /// pointer is null. This is because the absolute address in memory is not
21
- /// known at compile time. If the nullness of the pointer cannot be
22
- /// determined, this method will panic.
23
- ///
24
- /// In-bounds pointers are never null, so the method will never panic for
25
- /// such pointers.
8
+ #[ doc = include_str ! ( "docs/is_null.md" ) ]
26
9
///
27
10
/// # Examples
28
11
///
@@ -1906,53 +1889,10 @@ impl<T> *mut [T] {
1906
1889
unsafe { index. get_unchecked_mut ( self ) }
1907
1890
}
1908
1891
1909
- /// Returns `None` if the pointer is null, or else returns a shared slice to
1910
- /// the value wrapped in `Some`. In contrast to [`as_ref`], this does not require
1911
- /// that the value has to be initialized.
1892
+ #[ doc = include_str ! ( "docs/as_uninit_slice.md" ) ]
1912
1893
///
1894
+ /// # See Also
1913
1895
/// For the mutable counterpart see [`as_uninit_slice_mut`].
1914
- ///
1915
- /// [`as_ref`]: pointer#method.as_ref-1
1916
- /// [`as_uninit_slice_mut`]: #method.as_uninit_slice_mut
1917
- ///
1918
- /// # Safety
1919
- ///
1920
- /// When calling this method, you have to ensure that *either* the pointer is null *or*
1921
- /// all of the following is true:
1922
- ///
1923
- /// * The pointer must be [valid] for reads for `ptr.len() * size_of::<T>()` many bytes,
1924
- /// and it must be properly aligned. This means in particular:
1925
- ///
1926
- /// * The entire memory range of this slice must be contained within a single [allocation]!
1927
- /// Slices can never span across multiple allocations.
1928
- ///
1929
- /// * The pointer must be aligned even for zero-length slices. One
1930
- /// reason for this is that enum layout optimizations may rely on references
1931
- /// (including slices of any length) being aligned and non-null to distinguish
1932
- /// them from other data. You can obtain a pointer that is usable as `data`
1933
- /// for zero-length slices using [`NonNull::dangling()`].
1934
- ///
1935
- /// * The total size `ptr.len() * size_of::<T>()` of the slice must be no larger than `isize::MAX`.
1936
- /// See the safety documentation of [`pointer::offset`].
1937
- ///
1938
- /// * You must enforce Rust's aliasing rules, since the returned lifetime `'a` is
1939
- /// arbitrarily chosen and does not necessarily reflect the actual lifetime of the data.
1940
- /// In particular, while this reference exists, the memory the pointer points to must
1941
- /// not get mutated (except inside `UnsafeCell`).
1942
- ///
1943
- /// This applies even if the result of this method is unused!
1944
- ///
1945
- /// See also [`slice::from_raw_parts`][].
1946
- ///
1947
- /// [valid]: crate::ptr#safety
1948
- /// [allocation]: crate::ptr#allocation
1949
- ///
1950
- /// # Panics during const evaluation
1951
- ///
1952
- /// This method will panic during const evaluation if the pointer cannot be
1953
- /// determined to be null or not. See [`is_null`] for more information.
1954
- ///
1955
- /// [`is_null`]: #method.is_null-1
1956
1896
#[ inline]
1957
1897
#[ unstable( feature = "ptr_as_uninit" , issue = "75402" ) ]
1958
1898
pub const unsafe fn as_uninit_slice < ' a > ( self ) -> Option < & ' a [ MaybeUninit < T > ] > {
0 commit comments