offset_from / sub_ptr docs: emphasize that pointers must be in the sa… · qinheping/verify-rust-std@c80bb77 (original) (raw)

3 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -582,7 +582,7 @@ impl<T: ?Sized> *const T {
582 582 intrinsics::ptr_mask(self.cast::<()>(), mask).with_metadata_of(self)
583 583 }
584 584
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
586 586 /// units of T: the distance in bytes divided by `mem::size_of::()`.
587 587 ///
588 588 /// This is equivalent to `(self as isize - origin as isize) / (mem::size_of::() as isize)`,
@@ -677,7 +677,7 @@ impl<T: ?Sized> *const T {
677 677 unsafe { intrinsics::ptr_offset_from(self, origin) }
678 678 }
679 679
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
681 681 /// units of **bytes**.
682 682 ///
683 683 /// This is purely a convenience for casting to a `u8` pointer and
@@ -695,7 +695,7 @@ impl<T: ?Sized> *const T {
695 695 unsafe { self.cast::<u8>().offset_from(origin.cast::<u8>()) }
696 696 }
697 697
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
699 699 /// `self` is equal to or greater than `origin`*. The returned value is in
700 700 /// units of T: the distance in bytes is divided by `mem::size_of::()`.
701 701 ///
@@ -790,7 +790,7 @@ impl<T: ?Sized> *const T {
790 790 unsafe { intrinsics::ptr_offset_from_unsigned(self, origin) }
791 791 }
792 792
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
794 794 /// `self` is equal to or greater than `origin`*. The returned value is in
795 795 /// units of **bytes**.
796 796 ///
Original file line number Diff line number Diff line change
@@ -746,7 +746,7 @@ impl<T: ?Sized> *mut T {
746 746 (self as *const T).guaranteed_ne(other as _)
747 747 }
748 748
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
750 750 /// units of T: the distance in bytes divided by `mem::size_of::()`.
751 751 ///
752 752 /// This is equivalent to `(self as isize - origin as isize) / (mem::size_of::() as isize)`,
@@ -839,7 +839,7 @@ impl<T: ?Sized> *mut T {
839 839 unsafe { (self as *const T).offset_from(origin) }
840 840 }
841 841
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
843 843 /// units of **bytes**.
844 844 ///
845 845 /// This is purely a convenience for casting to a `u8` pointer and
@@ -857,7 +857,7 @@ impl<T: ?Sized> *mut T {
857 857 unsafe { self.cast::<u8>().offset_from(origin.cast::<u8>()) }
858 858 }
859 859
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
861 861 /// `self` is equal to or greater than `origin`*. The returned value is in
862 862 /// units of T: the distance in bytes is divided by `mem::size_of::()`.
863 863 ///
@@ -930,7 +930,7 @@ impl<T: ?Sized> *mut T {
930 930 unsafe { (self as *const T).sub_ptr(origin) }
931 931 }
932 932
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
934 934 /// `self` is equal to or greater than `origin`*. The returned value is in
935 935 /// units of **bytes**.
936 936 ///
Original file line number Diff line number Diff line change
@@ -676,7 +676,7 @@ impl<T: ?Sized> NonNull {
676 676 unsafe { NonNull { pointer: self.pointer.byte_sub(count) } }
677 677 }
678 678
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
680 680 /// units of T: the distance in bytes divided by `mem::size_of::()`.
681 681 ///
682 682 /// This is equivalent to `(self as isize - origin as isize) / (mem::size_of::() as isize)`,
@@ -773,7 +773,7 @@ impl<T: ?Sized> NonNull {
773 773 unsafe { self.pointer.offset_from(origin.pointer) }
774 774 }
775 775
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
777 777 /// units of **bytes**.
778 778 ///
779 779 /// This is purely a convenience for casting to a `u8` pointer and
@@ -793,7 +793,7 @@ impl<T: ?Sized> NonNull {
793 793
794 794 // N.B. `wrapping_offset``, `wrapping_add`, etc are not implemented because they can wrap to null
795 795
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
797 797 /// `self` is equal to or greater than `origin`*. The returned value is in
798 798 /// units of T: the distance in bytes is divided by `mem::size_of::()`.
799 799 ///
@@ -866,7 +866,7 @@ impl<T: ?Sized> NonNull {
866 866 unsafe { self.pointer.sub_ptr(subtracted.pointer) }
867 867 }
868 868
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
870 870 /// `self` is equal to or greater than `origin`*. The returned value is in
871 871 /// units of **bytes**.
872 872 ///