Skip to content

Commit c80bb77

Browse files
committed
offset_from / sub_ptr docs: emphasize that pointers must be in the same allocation
1 parent 861009d commit c80bb77

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

core/src/ptr/const_ptr.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ impl<T: ?Sized> *const T {
582582
intrinsics::ptr_mask(self.cast::<()>(), mask).with_metadata_of(self)
583583
}
584584

585-
/// Calculates the distance between two pointers. The returned value is in
585+
/// Calculates the distance between two pointers within the same allocation. The returned value is in
586586
/// units of T: the distance in bytes divided by `mem::size_of::<T>()`.
587587
///
588588
/// This is equivalent to `(self as isize - origin as isize) / (mem::size_of::<T>() as isize)`,
@@ -677,7 +677,7 @@ impl<T: ?Sized> *const T {
677677
unsafe { intrinsics::ptr_offset_from(self, origin) }
678678
}
679679

680-
/// Calculates the distance between two pointers. The returned value is in
680+
/// Calculates the distance between two pointers within the same allocation. The returned value is in
681681
/// units of **bytes**.
682682
///
683683
/// This is purely a convenience for casting to a `u8` pointer and
@@ -695,7 +695,7 @@ impl<T: ?Sized> *const T {
695695
unsafe { self.cast::<u8>().offset_from(origin.cast::<u8>()) }
696696
}
697697

698-
/// Calculates the distance between two pointers, *where it's known that
698+
/// Calculates the distance between two pointers within the same allocation, *where it's known that
699699
/// `self` is equal to or greater than `origin`*. The returned value is in
700700
/// units of T: the distance in bytes is divided by `mem::size_of::<T>()`.
701701
///
@@ -790,7 +790,7 @@ impl<T: ?Sized> *const T {
790790
unsafe { intrinsics::ptr_offset_from_unsigned(self, origin) }
791791
}
792792

793-
/// Calculates the distance between two pointers, *where it's known that
793+
/// Calculates the distance between two pointers within the same allocation, *where it's known that
794794
/// `self` is equal to or greater than `origin`*. The returned value is in
795795
/// units of **bytes**.
796796
///

core/src/ptr/mut_ptr.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ impl<T: ?Sized> *mut T {
746746
(self as *const T).guaranteed_ne(other as _)
747747
}
748748

749-
/// Calculates the distance between two pointers. The returned value is in
749+
/// Calculates the distance between two pointers within the same allocation. The returned value is in
750750
/// units of T: the distance in bytes divided by `mem::size_of::<T>()`.
751751
///
752752
/// This is equivalent to `(self as isize - origin as isize) / (mem::size_of::<T>() as isize)`,
@@ -839,7 +839,7 @@ impl<T: ?Sized> *mut T {
839839
unsafe { (self as *const T).offset_from(origin) }
840840
}
841841

842-
/// Calculates the distance between two pointers. The returned value is in
842+
/// Calculates the distance between two pointers within the same allocation. The returned value is in
843843
/// units of **bytes**.
844844
///
845845
/// This is purely a convenience for casting to a `u8` pointer and
@@ -857,7 +857,7 @@ impl<T: ?Sized> *mut T {
857857
unsafe { self.cast::<u8>().offset_from(origin.cast::<u8>()) }
858858
}
859859

860-
/// Calculates the distance between two pointers, *where it's known that
860+
/// Calculates the distance between two pointers within the same allocation, *where it's known that
861861
/// `self` is equal to or greater than `origin`*. The returned value is in
862862
/// units of T: the distance in bytes is divided by `mem::size_of::<T>()`.
863863
///
@@ -930,7 +930,7 @@ impl<T: ?Sized> *mut T {
930930
unsafe { (self as *const T).sub_ptr(origin) }
931931
}
932932

933-
/// Calculates the distance between two pointers, *where it's known that
933+
/// Calculates the distance between two pointers within the same allocation, *where it's known that
934934
/// `self` is equal to or greater than `origin`*. The returned value is in
935935
/// units of **bytes**.
936936
///

core/src/ptr/non_null.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ impl<T: ?Sized> NonNull<T> {
676676
unsafe { NonNull { pointer: self.pointer.byte_sub(count) } }
677677
}
678678

679-
/// Calculates the distance between two pointers. The returned value is in
679+
/// Calculates the distance between two pointers within the same allocation. The returned value is in
680680
/// units of T: the distance in bytes divided by `mem::size_of::<T>()`.
681681
///
682682
/// This is equivalent to `(self as isize - origin as isize) / (mem::size_of::<T>() as isize)`,
@@ -773,7 +773,7 @@ impl<T: ?Sized> NonNull<T> {
773773
unsafe { self.pointer.offset_from(origin.pointer) }
774774
}
775775

776-
/// Calculates the distance between two pointers. The returned value is in
776+
/// Calculates the distance between two pointers within the same allocation. The returned value is in
777777
/// units of **bytes**.
778778
///
779779
/// This is purely a convenience for casting to a `u8` pointer and
@@ -793,7 +793,7 @@ impl<T: ?Sized> NonNull<T> {
793793

794794
// N.B. `wrapping_offset``, `wrapping_add`, etc are not implemented because they can wrap to null
795795

796-
/// Calculates the distance between two pointers, *where it's known that
796+
/// Calculates the distance between two pointers within the same allocation, *where it's known that
797797
/// `self` is equal to or greater than `origin`*. The returned value is in
798798
/// units of T: the distance in bytes is divided by `mem::size_of::<T>()`.
799799
///
@@ -866,7 +866,7 @@ impl<T: ?Sized> NonNull<T> {
866866
unsafe { self.pointer.sub_ptr(subtracted.pointer) }
867867
}
868868

869-
/// Calculates the distance between two pointers, *where it's known that
869+
/// Calculates the distance between two pointers within the same allocation, *where it's known that
870870
/// `self` is equal to or greater than `origin`*. The returned value is in
871871
/// units of **bytes**.
872872
///

0 commit comments

Comments
 (0)