Skip to content

Rename sub_ptr to offset_from_unsigned in docs #140391

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion library/alloc/src/vec/into_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ impl<T, A: Allocator> IntoIter<T, A> {

// SAFETY: This allocation originally came from a `Vec`, so it passes
// all those checks. We have `this.buf` ≤ `this.ptr` ≤ `this.end`,
// so the `sub_ptr`s below cannot wrap, and will produce a well-formed
// so the `offset_from_unsigned`s below cannot wrap, and will produce a well-formed
// range. `end` ≤ `buf + cap`, so the range will be in-bounds.
// Taking `alloc` is ok because nothing else is going to look at it,
// since our `Drop` impl isn't going to run so there's no more code.
Expand Down
2 changes: 1 addition & 1 deletion library/alloc/src/vec/splice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl<I: Iterator, A: Allocator> Drop for Splice<'_, I, A> {
// and moving things into the final place.
// Which means we can replace the slice::Iter with pointers that won't point to deallocated
// memory, so that Drain::drop is still allowed to call iter.len(), otherwise it would break
// the ptr.sub_ptr contract.
// the ptr.offset_from_unsigned contract.
self.drain.iter = (&[]).iter();

unsafe {
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/intrinsics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2996,7 +2996,7 @@ pub unsafe fn nontemporal_store<T>(ptr: *mut T, val: T);
#[rustc_intrinsic]
pub const unsafe fn ptr_offset_from<T>(ptr: *const T, base: *const T) -> isize;

/// See documentation of `<*const T>::sub_ptr` for details.
/// See documentation of `<*const T>::offset_from_unsigned` for details.
#[rustc_nounwind]
#[rustc_intrinsic]
#[rustc_intrinsic_const_stable_indirect]
Expand Down
6 changes: 3 additions & 3 deletions library/core/src/ptr/const_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -804,8 +804,8 @@ impl<T: ?Sized> *const T {
/// units of **bytes**.
///
/// This is purely a convenience for casting to a `u8` pointer and
/// using [`sub_ptr`][pointer::offset_from_unsigned] on it. See that method for
/// documentation and safety requirements.
/// 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.
Expand All @@ -814,7 +814,7 @@ impl<T: ?Sized> *const T {
#[inline]
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
pub const unsafe fn byte_offset_from_unsigned<U: ?Sized>(self, origin: *const U) -> usize {
// SAFETY: the caller must uphold the safety contract for `sub_ptr`.
// SAFETY: the caller must uphold the safety contract for `offset_from_unsigned`.
unsafe { self.cast::<u8>().offset_from_unsigned(origin.cast::<u8>()) }
}

Expand Down
9 changes: 5 additions & 4 deletions library/core/src/ptr/mut_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,7 @@ impl<T: ?Sized> *mut T {
///
/// // This would be incorrect, as the pointers are not correctly ordered:
/// // ptr1.offset_from(ptr2)
/// ```
#[stable(feature = "ptr_sub_ptr", since = "1.87.0")]
#[rustc_const_stable(feature = "const_ptr_sub_ptr", since = "1.87.0")]
#[inline]
Expand All @@ -945,7 +946,7 @@ impl<T: ?Sized> *mut T {
where
T: Sized,
{
// SAFETY: the caller must uphold the safety contract for `sub_ptr`.
// SAFETY: the caller must uphold the safety contract for `offset_from_unsigned`.
unsafe { (self as *const T).offset_from_unsigned(origin) }
}

Expand All @@ -954,8 +955,8 @@ impl<T: ?Sized> *mut T {
/// units of **bytes**.
///
/// This is purely a convenience for casting to a `u8` pointer and
/// using [`sub_ptr`][pointer::offset_from_unsigned] on it. See that method for
/// documentation and safety requirements.
/// 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.
Expand All @@ -964,7 +965,7 @@ impl<T: ?Sized> *mut T {
#[inline]
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
pub const unsafe fn byte_offset_from_unsigned<U: ?Sized>(self, origin: *mut U) -> usize {
// SAFETY: the caller must uphold the safety contract for `byte_sub_ptr`.
// SAFETY: the caller must uphold the safety contract for `byte_offset_from_unsigned`.
unsafe { (self as *const T).byte_offset_from_unsigned(origin) }
}

Expand Down
8 changes: 4 additions & 4 deletions library/core/src/ptr/non_null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ impl<T: ?Sized> NonNull<T> {
where
T: Sized,
{
// SAFETY: the caller must uphold the safety contract for `sub_ptr`.
// SAFETY: the caller must uphold the safety contract for `offset_from_unsigned`.
unsafe { self.as_ptr().offset_from_unsigned(subtracted.as_ptr()) }
}

Expand All @@ -915,8 +915,8 @@ impl<T: ?Sized> NonNull<T> {
/// units of **bytes**.
///
/// This is purely a convenience for casting to a `u8` pointer and
/// using [`sub_ptr`][NonNull::offset_from_unsigned] on it. See that method for
/// documentation and safety requirements.
/// 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.
Expand All @@ -925,7 +925,7 @@ impl<T: ?Sized> NonNull<T> {
#[stable(feature = "ptr_sub_ptr", since = "1.87.0")]
#[rustc_const_stable(feature = "const_ptr_sub_ptr", since = "1.87.0")]
pub const unsafe fn byte_offset_from_unsigned<U: ?Sized>(self, origin: NonNull<U>) -> usize {
// SAFETY: the caller must uphold the safety contract for `byte_sub_ptr`.
// SAFETY: the caller must uphold the safety contract for `byte_offset_from_unsigned`.
unsafe { self.as_ptr().byte_offset_from_unsigned(origin.as_ptr()) }
}

Expand Down
Loading