diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs index 455eed6f3f6a9..87ba0067b9ba4 100644 --- a/library/core/src/ptr/const_ptr.rs +++ b/library/core/src/ptr/const_ptr.rs @@ -393,11 +393,14 @@ impl *const T { /// `count` is in units of **bytes**. /// /// This is purely a convenience for casting to a `u8` pointer and - /// using [offset][pointer::offset] on it. See that method for documentation - /// and safety requirements. + /// using [offset][pointer::offset] on it. /// /// For non-`Sized` pointees this operation changes only the data pointer, /// leaving the metadata untouched. + /// + /// # Safety + /// + /// See [offset][pointer::offset] for documentation and safety requirements. #[must_use] #[inline(always)] #[stable(feature = "pointer_byte_offsets", since = "1.75.0")] @@ -626,11 +629,14 @@ impl *const T { /// units of **bytes**. /// /// This is purely a convenience for casting to a `u8` pointer and - /// using [`offset_from`][pointer::offset_from] on it. See that method for - /// documentation and safety requirements. + /// using [`offset_from`][pointer::offset_from] on it. /// /// For non-`Sized` pointees this operation considers only the data pointers, /// ignoring the metadata. + /// + /// # Safety + /// + /// See [`offset_from`][pointer::offset_from] for documentation and safety requirements. #[inline(always)] #[stable(feature = "pointer_byte_offsets", since = "1.75.0")] #[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "1.75.0")] @@ -738,10 +744,13 @@ impl *const T { /// /// This is purely a convenience for casting to a `u8` pointer and /// using [`offset_from_unsigned`][pointer::offset_from_unsigned] on it. - /// See that method for documentation and safety requirements. /// /// For non-`Sized` pointees this operation considers only the data pointers, /// ignoring the metadata. + /// + /// # Safety + /// + /// See [`offset_from_unsigned`][pointer::offset_from_unsigned] for documentation and safety requirements. #[stable(feature = "ptr_sub_ptr", since = "1.87.0")] #[rustc_const_stable(feature = "const_ptr_sub_ptr", since = "1.87.0")] #[inline] @@ -875,11 +884,14 @@ impl *const T { /// `count` is in units of bytes. /// /// This is purely a convenience for casting to a `u8` pointer and - /// using [add][pointer::add] on it. See that method for documentation - /// and safety requirements. + /// using [add][pointer::add] on it. /// /// For non-`Sized` pointees this operation changes only the data pointer, /// leaving the metadata untouched. + /// + /// # Safety + /// + /// See [add][pointer::add] for documentation and safety requirements. #[must_use] #[inline(always)] #[stable(feature = "pointer_byte_offsets", since = "1.75.0")] @@ -960,11 +972,14 @@ impl *const T { /// `count` is in units of bytes. /// /// This is purely a convenience for casting to a `u8` pointer and - /// using [sub][pointer::sub] on it. See that method for documentation - /// and safety requirements. + /// using [sub][pointer::sub] on it. /// /// For non-`Sized` pointees this operation changes only the data pointer, /// leaving the metadata untouched. + /// + /// # Safety + /// + /// See [sub][pointer::sub] for documentation and safety requirements. #[must_use] #[inline(always)] #[stable(feature = "pointer_byte_offsets", since = "1.75.0")] @@ -1137,6 +1152,8 @@ impl *const T { /// Reads the value from `self` without moving it. This leaves the /// memory in `self` unchanged. /// + /// # Safety + /// /// See [`ptr::read`] for safety concerns and examples. /// /// [`ptr::read`]: crate::ptr::read() @@ -1159,6 +1176,8 @@ impl *const T { /// to not be elided or reordered by the compiler across other volatile /// operations. /// + /// # Safety + /// /// See [`ptr::read_volatile`] for safety concerns and examples. /// /// [`ptr::read_volatile`]: crate::ptr::read_volatile() @@ -1179,6 +1198,8 @@ impl *const T { /// /// Unlike `read`, the pointer may be unaligned. /// + /// # Safety + /// /// See [`ptr::read_unaligned`] for safety concerns and examples. /// /// [`ptr::read_unaligned`]: crate::ptr::read_unaligned() @@ -1199,6 +1220,8 @@ impl *const T { /// /// NOTE: this has the *same* argument order as [`ptr::copy`]. /// + /// # Safety + /// /// See [`ptr::copy`] for safety concerns and examples. /// /// [`ptr::copy`]: crate::ptr::copy() @@ -1219,6 +1242,8 @@ impl *const T { /// /// NOTE: this has the *same* argument order as [`ptr::copy_nonoverlapping`]. /// + /// # Safety + /// /// See [`ptr::copy_nonoverlapping`] for safety concerns and examples. /// /// [`ptr::copy_nonoverlapping`]: crate::ptr::copy_nonoverlapping() @@ -1497,6 +1522,8 @@ impl *const [T] { /// Returns a raw pointer to an element or subslice, without doing bounds /// checking. /// + /// # Safety + /// /// Calling this method with an [out-of-bounds index] or when `self` is not dereferenceable /// is *[undefined behavior]* even if the resulting pointer is not used. /// diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs index ca37c79bc1b04..e778f307f99b7 100644 --- a/library/core/src/ptr/mut_ptr.rs +++ b/library/core/src/ptr/mut_ptr.rs @@ -397,11 +397,14 @@ impl *mut T { /// `count` is in units of **bytes**. /// /// This is purely a convenience for casting to a `u8` pointer and - /// using [offset][pointer::offset] on it. See that method for documentation - /// and safety requirements. + /// using [offset][pointer::offset] on it. /// /// For non-`Sized` pointees this operation changes only the data pointer, /// leaving the metadata untouched. + /// + /// # Safety + /// + /// See [offset][pointer::offset] for documentation and safety requirements. #[must_use] #[inline(always)] #[stable(feature = "pointer_byte_offsets", since = "1.75.0")] @@ -806,11 +809,14 @@ impl *mut T { /// units of **bytes**. /// /// This is purely a convenience for casting to a `u8` pointer and - /// using [`offset_from`][pointer::offset_from] on it. See that method for - /// documentation and safety requirements. + /// using [`offset_from`][pointer::offset_from] on it. /// /// For non-`Sized` pointees this operation considers only the data pointers, /// ignoring the metadata. + /// + /// # Safety + /// + /// See [`offset_from`][pointer::offset_from] for documentation and safety requirements. #[inline(always)] #[stable(feature = "pointer_byte_offsets", since = "1.75.0")] #[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "1.75.0")] @@ -897,10 +903,13 @@ impl *mut T { /// /// This is purely a convenience for casting to a `u8` pointer and /// using [`offset_from_unsigned`][pointer::offset_from_unsigned] on it. - /// See that method for documentation and safety requirements. /// /// For non-`Sized` pointees this operation considers only the data pointers, /// ignoring the metadata. + /// + /// # Safety + /// + /// See [`offset_from_unsigned`][pointer::offset_from_unsigned] for documentation and safety requirements. #[stable(feature = "ptr_sub_ptr", since = "1.87.0")] #[rustc_const_stable(feature = "const_ptr_sub_ptr", since = "1.87.0")] #[inline] @@ -974,11 +983,14 @@ impl *mut T { /// `count` is in units of bytes. /// /// This is purely a convenience for casting to a `u8` pointer and - /// using [add][pointer::add] on it. See that method for documentation - /// and safety requirements. + /// using [add][pointer::add] on it. /// /// For non-`Sized` pointees this operation changes only the data pointer, /// leaving the metadata untouched. + /// + /// # Safety + /// + /// See [`add`][pointer::add] for documentation and safety requirements. #[must_use] #[inline(always)] #[stable(feature = "pointer_byte_offsets", since = "1.75.0")] @@ -1059,11 +1071,14 @@ impl *mut T { /// `count` is in units of bytes. /// /// This is purely a convenience for casting to a `u8` pointer and - /// using [sub][pointer::sub] on it. See that method for documentation - /// and safety requirements. + /// using [sub][pointer::sub] on it. /// /// For non-`Sized` pointees this operation changes only the data pointer, /// leaving the metadata untouched. + /// + /// # Safety + /// + /// See [`sub`][pointer::sub] for documentation and safety requirements. #[must_use] #[inline(always)] #[stable(feature = "pointer_byte_offsets", since = "1.75.0")] @@ -1230,6 +1245,8 @@ impl *mut T { /// Reads the value from `self` without moving it. This leaves the /// memory in `self` unchanged. /// + /// # Safety + /// /// See [`ptr::read`] for safety concerns and examples. /// /// [`ptr::read`]: crate::ptr::read() @@ -1252,6 +1269,8 @@ impl *mut T { /// to not be elided or reordered by the compiler across other volatile /// operations. /// + /// # Safety + /// /// See [`ptr::read_volatile`] for safety concerns and examples. /// /// [`ptr::read_volatile`]: crate::ptr::read_volatile() @@ -1272,6 +1291,8 @@ impl *mut T { /// /// Unlike `read`, the pointer may be unaligned. /// + /// # Safety + /// /// See [`ptr::read_unaligned`] for safety concerns and examples. /// /// [`ptr::read_unaligned`]: crate::ptr::read_unaligned() @@ -1292,6 +1313,8 @@ impl *mut T { /// /// NOTE: this has the *same* argument order as [`ptr::copy`]. /// + /// # Safety + /// /// See [`ptr::copy`] for safety concerns and examples. /// /// [`ptr::copy`]: crate::ptr::copy() @@ -1312,6 +1335,8 @@ impl *mut T { /// /// NOTE: this has the *same* argument order as [`ptr::copy_nonoverlapping`]. /// + /// # Safety + /// /// See [`ptr::copy_nonoverlapping`] for safety concerns and examples. /// /// [`ptr::copy_nonoverlapping`]: crate::ptr::copy_nonoverlapping() @@ -1332,6 +1357,8 @@ impl *mut T { /// /// NOTE: this has the *opposite* argument order of [`ptr::copy`]. /// + /// # Safety + /// /// See [`ptr::copy`] for safety concerns and examples. /// /// [`ptr::copy`]: crate::ptr::copy() @@ -1352,6 +1379,8 @@ impl *mut T { /// /// NOTE: this has the *opposite* argument order of [`ptr::copy_nonoverlapping`]. /// + /// # Safety + /// /// See [`ptr::copy_nonoverlapping`] for safety concerns and examples. /// /// [`ptr::copy_nonoverlapping`]: crate::ptr::copy_nonoverlapping() @@ -1369,6 +1398,8 @@ impl *mut T { /// Executes the destructor (if any) of the pointed-to value. /// + /// # Safety + /// /// See [`ptr::drop_in_place`] for safety concerns and examples. /// /// [`ptr::drop_in_place`]: crate::ptr::drop_in_place() @@ -1387,6 +1418,8 @@ impl *mut T { /// Overwrites a memory location with the given value without reading or /// dropping the old value. /// + /// # Safety + /// /// See [`ptr::write`] for safety concerns and examples. /// /// [`ptr::write`]: crate::ptr::write() @@ -1405,6 +1438,8 @@ impl *mut T { /// Invokes memset on the specified pointer, setting `count * size_of::()` /// bytes of memory starting at `self` to `val`. /// + /// # Safety + /// /// See [`ptr::write_bytes`] for safety concerns and examples. /// /// [`ptr::write_bytes`]: crate::ptr::write_bytes() @@ -1428,6 +1463,8 @@ impl *mut T { /// to not be elided or reordered by the compiler across other volatile /// operations. /// + /// # Safety + /// /// See [`ptr::write_volatile`] for safety concerns and examples. /// /// [`ptr::write_volatile`]: crate::ptr::write_volatile() @@ -1448,6 +1485,8 @@ impl *mut T { /// /// Unlike `write`, the pointer may be unaligned. /// + /// # Safety + /// /// See [`ptr::write_unaligned`] for safety concerns and examples. /// /// [`ptr::write_unaligned`]: crate::ptr::write_unaligned() @@ -1466,6 +1505,8 @@ impl *mut T { /// Replaces the value at `self` with `src`, returning the old /// value, without dropping either. /// + /// # Safety + /// /// See [`ptr::replace`] for safety concerns and examples. /// /// [`ptr::replace`]: crate::ptr::replace() @@ -1484,6 +1525,8 @@ impl *mut T { /// deinitializing either. They may overlap, unlike `mem::swap` which is /// otherwise equivalent. /// + /// # Safety + /// /// See [`ptr::swap`] for safety concerns and examples. /// /// [`ptr::swap`]: crate::ptr::swap() @@ -1876,6 +1919,8 @@ impl *mut [T] { /// Returns a raw pointer to an element or subslice, without doing bounds /// checking. /// + /// # Safety + /// /// Calling this method with an [out-of-bounds index] or when `self` is not dereferenceable /// is *[undefined behavior]* even if the resulting pointer is not used. /// diff --git a/library/core/src/ptr/non_null.rs b/library/core/src/ptr/non_null.rs index 3cec204fd54cc..8762a077584b5 100644 --- a/library/core/src/ptr/non_null.rs +++ b/library/core/src/ptr/non_null.rs @@ -575,11 +575,14 @@ impl NonNull { /// `count` is in units of **bytes**. /// /// This is purely a convenience for casting to a `u8` pointer and - /// using [offset][pointer::offset] on it. See that method for documentation - /// and safety requirements. + /// using [offset][pointer::offset] on it. /// /// For non-`Sized` pointees this operation changes only the data pointer, /// leaving the metadata untouched. + /// + /// # Safety + /// + /// See [offset][pointer::offset] for documentation and safety requirements. #[must_use] #[inline(always)] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces @@ -630,11 +633,14 @@ impl NonNull { /// `count` is in units of bytes. /// /// This is purely a convenience for casting to a `u8` pointer and - /// using [`add`][NonNull::add] on it. See that method for documentation - /// and safety requirements. + /// using [`add`][NonNull::add] on it. /// /// For non-`Sized` pointees this operation changes only the data pointer, /// leaving the metadata untouched. + /// + /// # Safety + /// + /// See [`add`][NonNull::add] for documentation and safety requirements. #[must_use] #[inline(always)] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces @@ -690,11 +696,14 @@ impl NonNull { /// `count` is in units of bytes. /// /// This is purely a convenience for casting to a `u8` pointer and - /// using [`sub`][NonNull::sub] on it. See that method for documentation - /// and safety requirements. + /// using [`sub`][NonNull::sub] on it. /// /// For non-`Sized` pointees this operation changes only the data pointer, /// leaving the metadata untouched. + /// + /// # Safety + /// + /// See [`sub`][NonNull::sub] for documentation and safety requirements. #[must_use] #[inline(always)] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces @@ -809,11 +818,14 @@ impl NonNull { /// units of **bytes**. /// /// This is purely a convenience for casting to a `u8` pointer and - /// using [`offset_from`][NonNull::offset_from] on it. See that method for - /// documentation and safety requirements. + /// using [`offset_from`][NonNull::offset_from] on it. /// /// For non-`Sized` pointees this operation considers only the data pointers, /// ignoring the metadata. + /// + /// # Safety + /// + /// See [`offset_from`][NonNull::offset_from] for documentation and safety requirements. #[inline(always)] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces #[stable(feature = "non_null_convenience", since = "1.80.0")] @@ -902,10 +914,13 @@ impl NonNull { /// /// This is purely a convenience for casting to a `u8` pointer and /// using [`offset_from_unsigned`][NonNull::offset_from_unsigned] on it. - /// See that method for documentation and safety requirements. /// /// For non-`Sized` pointees this operation considers only the data pointers, /// ignoring the metadata. + /// + /// # Safety + /// + /// See [`offset_from_unsigned`][NonNull::offset_from_unsigned] for documentation and safety requirements. #[inline(always)] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces #[stable(feature = "ptr_sub_ptr", since = "1.87.0")] @@ -918,6 +933,8 @@ impl NonNull { /// Reads the value from `self` without moving it. This leaves the /// memory in `self` unchanged. /// + /// # Safety + /// /// See [`ptr::read`] for safety concerns and examples. /// /// [`ptr::read`]: crate::ptr::read() @@ -940,6 +957,8 @@ impl NonNull { /// to not be elided or reordered by the compiler across other volatile /// operations. /// + /// # Safety + /// /// See [`ptr::read_volatile`] for safety concerns and examples. /// /// [`ptr::read_volatile`]: crate::ptr::read_volatile() @@ -960,6 +979,8 @@ impl NonNull { /// /// Unlike `read`, the pointer may be unaligned. /// + /// # Safety + /// /// See [`ptr::read_unaligned`] for safety concerns and examples. /// /// [`ptr::read_unaligned`]: crate::ptr::read_unaligned() @@ -980,6 +1001,8 @@ impl NonNull { /// /// NOTE: this has the *same* argument order as [`ptr::copy`]. /// + /// # Safety + /// /// See [`ptr::copy`] for safety concerns and examples. /// /// [`ptr::copy`]: crate::ptr::copy() @@ -1000,6 +1023,8 @@ impl NonNull { /// /// NOTE: this has the *same* argument order as [`ptr::copy_nonoverlapping`]. /// + /// # Safety + /// /// See [`ptr::copy_nonoverlapping`] for safety concerns and examples. /// /// [`ptr::copy_nonoverlapping`]: crate::ptr::copy_nonoverlapping() @@ -1020,6 +1045,8 @@ impl NonNull { /// /// NOTE: this has the *opposite* argument order of [`ptr::copy`]. /// + /// # Safety + /// /// See [`ptr::copy`] for safety concerns and examples. /// /// [`ptr::copy`]: crate::ptr::copy() @@ -1040,6 +1067,8 @@ impl NonNull { /// /// NOTE: this has the *opposite* argument order of [`ptr::copy_nonoverlapping`]. /// + /// # Safety + /// /// See [`ptr::copy_nonoverlapping`] for safety concerns and examples. /// /// [`ptr::copy_nonoverlapping`]: crate::ptr::copy_nonoverlapping() @@ -1057,6 +1086,8 @@ impl NonNull { /// Executes the destructor (if any) of the pointed-to value. /// + /// # Safety + /// /// See [`ptr::drop_in_place`] for safety concerns and examples. /// /// [`ptr::drop_in_place`]: crate::ptr::drop_in_place() @@ -1074,6 +1105,8 @@ impl NonNull { /// Overwrites a memory location with the given value without reading or /// dropping the old value. /// + /// # Safety + /// /// See [`ptr::write`] for safety concerns and examples. /// /// [`ptr::write`]: crate::ptr::write() @@ -1092,6 +1125,8 @@ impl NonNull { /// Invokes memset on the specified pointer, setting `count * size_of::()` /// bytes of memory starting at `self` to `val`. /// + /// # Safety + /// /// See [`ptr::write_bytes`] for safety concerns and examples. /// /// [`ptr::write_bytes`]: crate::ptr::write_bytes() @@ -1115,6 +1150,8 @@ impl NonNull { /// to not be elided or reordered by the compiler across other volatile /// operations. /// + /// # Safety + /// /// See [`ptr::write_volatile`] for safety concerns and examples. /// /// [`ptr::write_volatile`]: crate::ptr::write_volatile() @@ -1135,6 +1172,8 @@ impl NonNull { /// /// Unlike `write`, the pointer may be unaligned. /// + /// # Safety + /// /// See [`ptr::write_unaligned`] for safety concerns and examples. /// /// [`ptr::write_unaligned`]: crate::ptr::write_unaligned() @@ -1153,6 +1192,8 @@ impl NonNull { /// Replaces the value at `self` with `src`, returning the old /// value, without dropping either. /// + /// # Safety + /// /// See [`ptr::replace`] for safety concerns and examples. /// /// [`ptr::replace`]: crate::ptr::replace() @@ -1171,6 +1212,8 @@ impl NonNull { /// deinitializing either. They may overlap, unlike `mem::swap` which is /// otherwise equivalent. /// + /// # Safety + /// /// See [`ptr::swap`] for safety concerns and examples. /// /// [`ptr::swap`]: crate::ptr::swap() @@ -1585,6 +1628,8 @@ impl NonNull<[T]> { /// Returns a raw pointer to an element or subslice, without doing bounds /// checking. /// + /// # Safety + /// /// Calling this method with an [out-of-bounds index] or when `self` is not dereferenceable /// is *[undefined behavior]* even if the resulting pointer is not used. ///