@@ -344,7 +344,7 @@ impl<T: ?Sized> *mut T {
344344 if self . is_null ( ) { None } else { Some ( unsafe { & * ( self as * const MaybeUninit < T > ) } ) }
345345 }
346346
347- /// Adds an offset to a pointer.
347+ /// Adds a signed offset to a pointer.
348348 ///
349349 /// `count` is in units of T; e.g., a `count` of 3 represents a pointer
350350 /// offset of `3 * size_of::<T>()` bytes.
@@ -353,7 +353,8 @@ impl<T: ?Sized> *mut T {
353353 ///
354354 /// If any of the following conditions are violated, the result is Undefined Behavior:
355355 ///
356- /// * The computed offset, `count * size_of::<T>()` bytes, must not overflow `isize`.
356+ /// * The offset in bytes, `count * size_of::<T>()`, computed on mathematical integers (without
357+ /// "wrapping around"), must fit in an `isize`.
357358 ///
358359 /// * If the computed offset is non-zero, then `self` must be derived from a pointer to some
359360 /// [allocated object], and the entire memory range between `self` and the result must be in
@@ -398,7 +399,7 @@ impl<T: ?Sized> *mut T {
398399 unsafe { intrinsics:: offset ( self , count) }
399400 }
400401
401- /// Calculates the offset from a pointer in bytes .
402+ /// Adds a signed offset in bytes to a pointer .
402403 ///
403404 /// `count` is in units of **bytes**.
404405 ///
@@ -418,7 +419,8 @@ impl<T: ?Sized> *mut T {
418419 unsafe { self . cast :: < u8 > ( ) . offset ( count) . with_metadata_of ( self ) }
419420 }
420421
421- /// Calculates the offset from a pointer using wrapping arithmetic.
422+ /// Adds a signed offset to a pointer using wrapping arithmetic.
423+ ///
422424 /// `count` is in units of T; e.g., a `count` of 3 represents a pointer
423425 /// offset of `3 * size_of::<T>()` bytes.
424426 ///
@@ -477,7 +479,7 @@ impl<T: ?Sized> *mut T {
477479 unsafe { intrinsics:: arith_offset ( self , count) as * mut T }
478480 }
479481
480- /// Calculates the offset from a pointer in bytes using wrapping arithmetic.
482+ /// Adds a signed offset in bytes to a pointer using wrapping arithmetic.
481483 ///
482484 /// `count` is in units of **bytes**.
483485 ///
@@ -885,7 +887,11 @@ impl<T: ?Sized> *mut T {
885887 unsafe { ( self as * const T ) . sub_ptr ( origin) }
886888 }
887889
888- /// Adds an offset to a pointer (convenience for `.offset(count as isize)`).
890+ /// Adds an unsigned offset to a pointer.
891+ ///
892+ /// This can only move the pointer forward (or not move it). If you need to move forward or
893+ /// backward depending on the value, then you might want [`offset`](#method.offset) instead
894+ /// which takes a signed offset.
889895 ///
890896 /// `count` is in units of T; e.g., a `count` of 3 represents a pointer
891897 /// offset of `3 * size_of::<T>()` bytes.
@@ -894,7 +900,8 @@ impl<T: ?Sized> *mut T {
894900 ///
895901 /// If any of the following conditions are violated, the result is Undefined Behavior:
896902 ///
897- /// * The computed offset, `count * size_of::<T>()` bytes, must not overflow `isize`.
903+ /// * The offset in bytes, `count * size_of::<T>()`, computed on mathematical integers (without
904+ /// "wrapping around"), must fit in an `isize`.
898905 ///
899906 /// * If the computed offset is non-zero, then `self` must be derived from a pointer to some
900907 /// [allocated object], and the entire memory range between `self` and the result must be in
@@ -937,7 +944,7 @@ impl<T: ?Sized> *mut T {
937944 unsafe { intrinsics:: offset ( self , count) }
938945 }
939946
940- /// Calculates the offset from a pointer in bytes (convenience for `.byte_offset(count as isize)`) .
947+ /// Adds an unsigned offset in bytes to a pointer .
941948 ///
942949 /// `count` is in units of bytes.
943950 ///
@@ -957,8 +964,11 @@ impl<T: ?Sized> *mut T {
957964 unsafe { self . cast :: < u8 > ( ) . add ( count) . with_metadata_of ( self ) }
958965 }
959966
960- /// Subtracts an offset from a pointer (convenience for
961- /// `.offset((count as isize).wrapping_neg())`).
967+ /// Subtracts an unsigned offset from a pointer.
968+ ///
969+ /// This can only move the pointer backward (or not move it). If you need to move forward or
970+ /// backward depending on the value, then you might want [`offset`](#method.offset) instead
971+ /// which takes a signed offset.
962972 ///
963973 /// `count` is in units of T; e.g., a `count` of 3 represents a pointer
964974 /// offset of `3 * size_of::<T>()` bytes.
@@ -967,7 +977,8 @@ impl<T: ?Sized> *mut T {
967977 ///
968978 /// If any of the following conditions are violated, the result is Undefined Behavior:
969979 ///
970- /// * The computed offset, `count * size_of::<T>()` bytes, must not overflow `isize`.
980+ /// * The offset in bytes, `count * size_of::<T>()`, computed on mathematical integers (without
981+ /// "wrapping around"), must fit in an `isize`.
971982 ///
972983 /// * If the computed offset is non-zero, then `self` must be derived from a pointer to some
973984 /// [allocated object], and the entire memory range between `self` and the result must be in
@@ -1018,8 +1029,7 @@ impl<T: ?Sized> *mut T {
10181029 }
10191030 }
10201031
1021- /// Calculates the offset from a pointer in bytes (convenience for
1022- /// `.byte_offset((count as isize).wrapping_neg())`).
1032+ /// Subtracts an unsigned offset in bytes from a pointer.
10231033 ///
10241034 /// `count` is in units of bytes.
10251035 ///
@@ -1039,8 +1049,7 @@ impl<T: ?Sized> *mut T {
10391049 unsafe { self . cast :: < u8 > ( ) . sub ( count) . with_metadata_of ( self ) }
10401050 }
10411051
1042- /// Calculates the offset from a pointer using wrapping arithmetic.
1043- /// (convenience for `.wrapping_offset(count as isize)`)
1052+ /// Adds an unsigned offset to a pointer using wrapping arithmetic.
10441053 ///
10451054 /// `count` is in units of T; e.g., a `count` of 3 represents a pointer
10461055 /// offset of `3 * size_of::<T>()` bytes.
@@ -1099,8 +1108,7 @@ impl<T: ?Sized> *mut T {
10991108 self . wrapping_offset ( count as isize )
11001109 }
11011110
1102- /// Calculates the offset from a pointer in bytes using wrapping arithmetic.
1103- /// (convenience for `.wrapping_byte_offset(count as isize)`)
1111+ /// Adds an unsigned offset in bytes to a pointer using wrapping arithmetic.
11041112 ///
11051113 /// `count` is in units of bytes.
11061114 ///
@@ -1117,8 +1125,7 @@ impl<T: ?Sized> *mut T {
11171125 self . cast :: < u8 > ( ) . wrapping_add ( count) . with_metadata_of ( self )
11181126 }
11191127
1120- /// Calculates the offset from a pointer using wrapping arithmetic.
1121- /// (convenience for `.wrapping_offset((count as isize).wrapping_neg())`)
1128+ /// Subtracts an unsigned offset from a pointer using wrapping arithmetic.
11221129 ///
11231130 /// `count` is in units of T; e.g., a `count` of 3 represents a pointer
11241131 /// offset of `3 * size_of::<T>()` bytes.
@@ -1177,8 +1184,7 @@ impl<T: ?Sized> *mut T {
11771184 self . wrapping_offset ( ( count as isize ) . wrapping_neg ( ) )
11781185 }
11791186
1180- /// Calculates the offset from a pointer in bytes using wrapping arithmetic.
1181- /// (convenience for `.wrapping_offset((count as isize).wrapping_neg())`)
1187+ /// Subtracts an unsigned offset in bytes from a pointer using wrapping arithmetic.
11821188 ///
11831189 /// `count` is in units of bytes.
11841190 ///
0 commit comments