@@ -355,8 +355,8 @@ impl<T: ?Sized> *const T {
355
355
///
356
356
/// If any of the following conditions are violated, the result is Undefined Behavior:
357
357
///
358
- /// * The computed offset, `count * size_of::<T>()` bytes (using unbounded arithmetic),
359
- /// must fit in an `isize`.
358
+ /// * The offset in bytes , `count * size_of::<T>()`, computed on mathematical integers (without
359
+ /// "wrapping around"), must fit in an `isize`.
360
360
///
361
361
/// * If the computed offset is non-zero, then `self` must be derived from a pointer to some
362
362
/// [allocated object], and the entire memory range between `self` and the result must be in
@@ -399,7 +399,7 @@ impl<T: ?Sized> *const T {
399
399
unsafe { intrinsics:: offset ( self , count) }
400
400
}
401
401
402
- /// Calculates the offset from a pointer in bytes .
402
+ /// Adds a signed offset in bytes to a pointer .
403
403
///
404
404
/// `count` is in units of **bytes**.
405
405
///
@@ -810,15 +810,19 @@ impl<T: ?Sized> *const T {
810
810
811
811
/// Adds an offset to a pointer.
812
812
///
813
+ /// This can only move the pointer forward (or not move it). If you need to move forward or
814
+ /// backward depending on the value, then you might want [`offset`](#method.offset) instead
815
+ /// which takes a signed offset.
816
+ ///
813
817
/// `count` is in units of T; e.g., a `count` of 3 represents a pointer
814
818
/// offset of `3 * size_of::<T>()` bytes.
815
819
///
816
820
/// # Safety
817
821
///
818
822
/// If any of the following conditions are violated, the result is Undefined Behavior:
819
823
///
820
- /// * The computed offset, `count * size_of::<T>()` bytes (using unbounded arithmetic),
821
- /// must fit in an `isize`.
824
+ /// * The offset in bytes , `count * size_of::<T>()`, computed on mathematical integers (without
825
+ /// "wrapping around"), must fit in an `isize`.
822
826
///
823
827
/// * If the computed offset is non-zero, then `self` must be derived from a pointer to some
824
828
/// [allocated object], and the entire memory range between `self` and the result must be in
@@ -861,7 +865,7 @@ impl<T: ?Sized> *const T {
861
865
unsafe { intrinsics:: offset ( self , count) }
862
866
}
863
867
864
- /// Calculates the offset from a pointer in bytes (convenience for `.byte_offset(count as isize)`) .
868
+ /// Adds an offset in bytes to a pointer .
865
869
///
866
870
/// `count` is in units of bytes.
867
871
///
@@ -884,15 +888,19 @@ impl<T: ?Sized> *const T {
884
888
885
889
/// Subtracts an offset from a pointer.
886
890
///
891
+ /// This can only move the pointer backward (or not move it). If you need to move forward or
892
+ /// backward depending on the value, then you might want [`offset`](#method.offset) instead
893
+ /// which takes a signed offset.
894
+ ///
887
895
/// `count` is in units of T; e.g., a `count` of 3 represents a pointer
888
896
/// offset of `3 * size_of::<T>()` bytes.
889
897
///
890
898
/// # Safety
891
899
///
892
900
/// If any of the following conditions are violated, the result is Undefined Behavior:
893
901
///
894
- /// * The computed offset, `count * size_of::<T>()` bytes (using unbounded arithmetic),
895
- /// must fit in an `isize`.
902
+ /// * The offset in bytes , `count * size_of::<T>()`, computed on mathematical integers (without
903
+ /// "wrapping around"), must fit in an `isize`.
896
904
///
897
905
/// * If the computed offset is non-zero, then `self` must be derived from a pointer to some
898
906
/// [allocated object], and the entire memory range between `self` and the result must be in
@@ -943,8 +951,7 @@ impl<T: ?Sized> *const T {
943
951
}
944
952
}
945
953
946
- /// Calculates the offset from a pointer in bytes (convenience for
947
- /// `.byte_offset((count as isize).wrapping_neg())`).
954
+ /// Subtracts an offset in bytes from a pointer.
948
955
///
949
956
/// `count` is in units of bytes.
950
957
///
0 commit comments