Skip to content

Commit a74ffa2

Browse files
committed
Rename sub_ptr to offset_from_unsigned in docs
1 parent a932eb3 commit a74ffa2

File tree

6 files changed

+14
-13
lines changed

6 files changed

+14
-13
lines changed

library/alloc/src/vec/into_iter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ impl<T, A: Allocator> IntoIter<T, A> {
168168

169169
// SAFETY: This allocation originally came from a `Vec`, so it passes
170170
// all those checks. We have `this.buf` ≤ `this.ptr` ≤ `this.end`,
171-
// so the `sub_ptr`s below cannot wrap, and will produce a well-formed
171+
// so the `offset_from_unsigned`s below cannot wrap, and will produce a well-formed
172172
// range. `end` ≤ `buf + cap`, so the range will be in-bounds.
173173
// Taking `alloc` is ok because nothing else is going to look at it,
174174
// since our `Drop` impl isn't going to run so there's no more code.

library/alloc/src/vec/splice.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl<I: Iterator, A: Allocator> Drop for Splice<'_, I, A> {
5959
// and moving things into the final place.
6060
// Which means we can replace the slice::Iter with pointers that won't point to deallocated
6161
// memory, so that Drain::drop is still allowed to call iter.len(), otherwise it would break
62-
// the ptr.sub_ptr contract.
62+
// the ptr.offset_from_unsigned contract.
6363
self.drain.iter = (&[]).iter();
6464

6565
unsafe {

library/core/src/intrinsics/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2996,7 +2996,7 @@ pub unsafe fn nontemporal_store<T>(ptr: *mut T, val: T);
29962996
#[rustc_intrinsic]
29972997
pub const unsafe fn ptr_offset_from<T>(ptr: *const T, base: *const T) -> isize;
29982998

2999-
/// See documentation of `<*const T>::sub_ptr` for details.
2999+
/// See documentation of `<*const T>::offset_from_unsigned` for details.
30003000
#[rustc_nounwind]
30013001
#[rustc_intrinsic]
30023002
#[rustc_intrinsic_const_stable_indirect]

library/core/src/ptr/const_ptr.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -804,8 +804,8 @@ impl<T: ?Sized> *const T {
804804
/// units of **bytes**.
805805
///
806806
/// This is purely a convenience for casting to a `u8` pointer and
807-
/// using [`sub_ptr`][pointer::offset_from_unsigned] on it. See that method for
808-
/// documentation and safety requirements.
807+
/// using [`offset_from_unsigned`][pointer::offset_from_unsigned] on it.
808+
/// See that method for documentation and safety requirements.
809809
///
810810
/// For non-`Sized` pointees this operation considers only the data pointers,
811811
/// ignoring the metadata.
@@ -814,7 +814,7 @@ impl<T: ?Sized> *const T {
814814
#[inline]
815815
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
816816
pub const unsafe fn byte_offset_from_unsigned<U: ?Sized>(self, origin: *const U) -> usize {
817-
// SAFETY: the caller must uphold the safety contract for `sub_ptr`.
817+
// SAFETY: the caller must uphold the safety contract for `offset_from_unsigned`.
818818
unsafe { self.cast::<u8>().offset_from_unsigned(origin.cast::<u8>()) }
819819
}
820820

library/core/src/ptr/mut_ptr.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,7 @@ impl<T: ?Sized> *mut T {
937937
///
938938
/// // This would be incorrect, as the pointers are not correctly ordered:
939939
/// // ptr1.offset_from(ptr2)
940+
/// ```
940941
#[stable(feature = "ptr_sub_ptr", since = "1.87.0")]
941942
#[rustc_const_stable(feature = "const_ptr_sub_ptr", since = "1.87.0")]
942943
#[inline]
@@ -945,7 +946,7 @@ impl<T: ?Sized> *mut T {
945946
where
946947
T: Sized,
947948
{
948-
// SAFETY: the caller must uphold the safety contract for `sub_ptr`.
949+
// SAFETY: the caller must uphold the safety contract for `offset_from_unsigned`.
949950
unsafe { (self as *const T).offset_from_unsigned(origin) }
950951
}
951952

@@ -954,8 +955,8 @@ impl<T: ?Sized> *mut T {
954955
/// units of **bytes**.
955956
///
956957
/// This is purely a convenience for casting to a `u8` pointer and
957-
/// using [`sub_ptr`][pointer::offset_from_unsigned] on it. See that method for
958-
/// documentation and safety requirements.
958+
/// using [`offset_from_unsigned`][pointer::offset_from_unsigned] on it.
959+
/// See that method for documentation and safety requirements.
959960
///
960961
/// For non-`Sized` pointees this operation considers only the data pointers,
961962
/// ignoring the metadata.
@@ -964,7 +965,7 @@ impl<T: ?Sized> *mut T {
964965
#[inline]
965966
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
966967
pub const unsafe fn byte_offset_from_unsigned<U: ?Sized>(self, origin: *mut U) -> usize {
967-
// SAFETY: the caller must uphold the safety contract for `byte_sub_ptr`.
968+
// SAFETY: the caller must uphold the safety contract for `byte_offset_from_unsigned`.
968969
unsafe { (self as *const T).byte_offset_from_unsigned(origin) }
969970
}
970971

library/core/src/ptr/non_null.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,7 @@ impl<T: ?Sized> NonNull<T> {
906906
where
907907
T: Sized,
908908
{
909-
// SAFETY: the caller must uphold the safety contract for `sub_ptr`.
909+
// SAFETY: the caller must uphold the safety contract for `offset_from_unsigned`.
910910
unsafe { self.as_ptr().offset_from_unsigned(subtracted.as_ptr()) }
911911
}
912912

@@ -915,7 +915,7 @@ impl<T: ?Sized> NonNull<T> {
915915
/// units of **bytes**.
916916
///
917917
/// This is purely a convenience for casting to a `u8` pointer and
918-
/// using [`sub_ptr`][NonNull::offset_from_unsigned] on it. See that method for
918+
/// using [`offset_from_unsigned`][NonNull::offset_from_unsigned] on it. See that method for
919919
/// documentation and safety requirements.
920920
///
921921
/// For non-`Sized` pointees this operation considers only the data pointers,
@@ -925,7 +925,7 @@ impl<T: ?Sized> NonNull<T> {
925925
#[stable(feature = "ptr_sub_ptr", since = "1.87.0")]
926926
#[rustc_const_stable(feature = "const_ptr_sub_ptr", since = "1.87.0")]
927927
pub const unsafe fn byte_offset_from_unsigned<U: ?Sized>(self, origin: NonNull<U>) -> usize {
928-
// SAFETY: the caller must uphold the safety contract for `byte_sub_ptr`.
928+
// SAFETY: the caller must uphold the safety contract for `byte_offset_from_unsigned`.
929929
unsafe { self.as_ptr().byte_offset_from_unsigned(origin.as_ptr()) }
930930
}
931931

0 commit comments

Comments
 (0)