diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs index 343b99cd4ca..6b8be00df6b 100644 --- a/library/core/src/ptr/const_ptr.rs +++ b/library/core/src/ptr/const_ptr.rs @@ -330,6 +330,10 @@ impl *const T { #[doc = include_str!("./docs/offset.md")] /// + /// Consider using [`wrapping_offset`](#method.wrapping_offset) instead if these constraints are + /// difficult to satisfy. The only advantage of this method is that it + /// enables more aggressive compiler optimizations. + /// /// # Examples /// /// ``` @@ -810,6 +814,10 @@ impl *const T { #[doc = include_str!("./docs/add.md")] /// + /// Consider using [`wrapping_add`](#method.wrapping_add) instead if these constraints are + /// difficult to satisfy. The only advantage of this method is that it + /// enables more aggressive compiler optimizations. + /// /// # Examples /// /// ``` @@ -885,6 +893,10 @@ impl *const T { #[doc = include_str!("./docs/sub.md")] /// + /// Consider using [`wrapping_sub`](#method.wrapping_sub) instead if these constraints are + /// difficult to satisfy. The only advantage of this method is that it + /// enables more aggressive compiler optimizations. + /// /// # Examples /// /// ``` diff --git a/library/core/src/ptr/docs/add.md b/library/core/src/ptr/docs/add.md index 0cea5aca6f4..807ebee6db1 100644 --- a/library/core/src/ptr/docs/add.md +++ b/library/core/src/ptr/docs/add.md @@ -25,9 +25,4 @@ Allocations can never be larger than `isize::MAX` bytes and they can only contai representable by `usize`, so technically the last condition implies the first two. This implies, for instance, that `vec.as_ptr().add(vec.len())` (for `vec: Vec`) is always safe. -Consider using [`wrapping_add`] instead if these constraints are -difficult to satisfy. The only advantage of this method is that it -enables more aggressive compiler optimizations. - -[`wrapping_add`]: #method.wrapping_add [allocation]: crate::ptr#allocation diff --git a/library/core/src/ptr/docs/offset.md b/library/core/src/ptr/docs/offset.md index c7b66c0625e..b1add36d377 100644 --- a/library/core/src/ptr/docs/offset.md +++ b/library/core/src/ptr/docs/offset.md @@ -22,9 +22,4 @@ Allocations can never be larger than `isize::MAX` bytes and they can only contai representable by `usize`, so technically the last condition implies the first two. This implies, for instance, that `vec.as_ptr().offset(vec.len() as isize)` (for `vec: Vec`) is always safe. -Consider using [`wrapping_offset`] instead if these constraints are -difficult to satisfy. The only advantage of this method is that it -enables more aggressive compiler optimizations. - -[`wrapping_offset`]: #method.wrapping_offset [allocation]: crate::ptr#allocation diff --git a/library/core/src/ptr/docs/sub.md b/library/core/src/ptr/docs/sub.md index 89733d71c4a..b8873b0cf36 100644 --- a/library/core/src/ptr/docs/sub.md +++ b/library/core/src/ptr/docs/sub.md @@ -24,9 +24,4 @@ This must fit in a `usize`. Allocations can never be larger than `isize::MAX` bytes and they can only contain addresses representable by `usize`, so technically the last condition implies the first two. -Consider using [`wrapping_sub`] instead if these constraints are -difficult to satisfy. The only advantage of this method is that it -enables more aggressive compiler optimizations. - -[`wrapping_sub`]: #method.wrapping_sub [allocation]: crate::ptr#allocation diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs index 30b74b50664..8d2e9746124 100644 --- a/library/core/src/ptr/mut_ptr.rs +++ b/library/core/src/ptr/mut_ptr.rs @@ -333,6 +333,10 @@ impl *mut T { #[doc = include_str!("./docs/offset.md")] /// + /// Consider using [`wrapping_offset`](#method.wrapping_offset) instead if these constraints are + /// difficult to satisfy. The only advantage of this method is that it + /// enables more aggressive compiler optimizations. + /// /// # Examples /// /// ``` @@ -908,6 +912,10 @@ impl *mut T { #[doc = include_str!("./docs/add.md")] /// + /// Consider using [`wrapping_add`](#method.wrapping_add) instead if these constraints are + /// difficult to satisfy. The only advantage of this method is that it + /// enables more aggressive compiler optimizations. + /// /// # Examples /// /// ``` @@ -983,6 +991,10 @@ impl *mut T { #[doc = include_str!("./docs/sub.md")] /// + /// Consider using [`wrapping_sub`](#method.wrapping_sub) instead if these constraints are + /// difficult to satisfy. The only advantage of this method is that it + /// enables more aggressive compiler optimizations. + /// /// # Examples /// /// ``` diff --git a/library/core/src/ptr/non_null.rs b/library/core/src/ptr/non_null.rs index b9b42c1efe0..66503d881bc 100644 --- a/library/core/src/ptr/non_null.rs +++ b/library/core/src/ptr/non_null.rs @@ -528,28 +528,7 @@ impl NonNull { if self.is_aligned_to(align_of::()) { Some(self.cast()) } else { None } } - /// Adds an offset to a pointer. - /// - /// `count` is in units of T; e.g., a `count` of 3 represents a pointer - /// offset of `3 * size_of::()` bytes. - /// - /// # Safety - /// - /// If any of the following conditions are violated, the result is Undefined Behavior: - /// - /// * The computed offset, `count * size_of::()` bytes, must not overflow `isize`. - /// - /// * If the computed offset is non-zero, then `self` must be derived from a pointer to some - /// [allocation], and the entire memory range between `self` and the result must be in - /// bounds of that allocation. In particular, this range must not "wrap around" the edge - /// of the address space. - /// - /// Allocations can never be larger than `isize::MAX` bytes, so if the computed offset - /// stays in bounds of the allocation, it is guaranteed to satisfy the first requirement. - /// This implies, for instance, that `vec.as_ptr().add(vec.len())` (for `vec: Vec`) is always - /// safe. - /// - /// [allocation]: crate::ptr#allocation + #[doc = include_str!("./docs/offset.md")] /// /// # Examples /// @@ -604,28 +583,7 @@ impl NonNull { unsafe { transmute(self.as_ptr().byte_offset(count)) } } - /// Adds an offset to a pointer (convenience for `.offset(count as isize)`). - /// - /// `count` is in units of T; e.g., a `count` of 3 represents a pointer - /// offset of `3 * size_of::()` bytes. - /// - /// # Safety - /// - /// If any of the following conditions are violated, the result is Undefined Behavior: - /// - /// * The computed offset, `count * size_of::()` bytes, must not overflow `isize`. - /// - /// * If the computed offset is non-zero, then `self` must be derived from a pointer to some - /// [allocation], and the entire memory range between `self` and the result must be in - /// bounds of that allocation. In particular, this range must not "wrap around" the edge - /// of the address space. - /// - /// Allocations can never be larger than `isize::MAX` bytes, so if the computed offset - /// stays in bounds of the allocation, it is guaranteed to satisfy the first requirement. - /// This implies, for instance, that `vec.as_ptr().add(vec.len())` (for `vec: Vec`) is always - /// safe. - /// - /// [allocation]: crate::ptr#allocation + #[doc = include_str!("./docs/add.md")] /// /// # Examples /// @@ -680,29 +638,7 @@ impl NonNull { unsafe { transmute(self.as_ptr().byte_add(count)) } } - /// Subtracts an offset from a pointer (convenience for - /// `.offset((count as isize).wrapping_neg())`). - /// - /// `count` is in units of T; e.g., a `count` of 3 represents a pointer - /// offset of `3 * size_of::()` bytes. - /// - /// # Safety - /// - /// If any of the following conditions are violated, the result is Undefined Behavior: - /// - /// * The computed offset, `count * size_of::()` bytes, must not overflow `isize`. - /// - /// * If the computed offset is non-zero, then `self` must be derived from a pointer to some - /// [allocation], and the entire memory range between `self` and the result must be in - /// bounds of that allocation. In particular, this range must not "wrap around" the edge - /// of the address space. - /// - /// Allocations can never be larger than `isize::MAX` bytes, so if the computed offset - /// stays in bounds of the allocation, it is guaranteed to satisfy the first requirement. - /// This implies, for instance, that `vec.as_ptr().add(vec.len())` (for `vec: Vec`) is always - /// safe. - /// - /// [allocation]: crate::ptr#allocation + #[doc = include_str!("./docs/sub.md")] /// /// # Examples ///