Skip to content

Commit 0e627de

Browse files
committed
various updates based on review
1 parent 5835079 commit 0e627de

File tree

2 files changed

+34
-20
lines changed

2 files changed

+34
-20
lines changed

Diff for: library/core/src/ptr/const_ptr.rs

+17-10
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,8 @@ impl<T: ?Sized> *const T {
355355
///
356356
/// If any of the following conditions are violated, the result is Undefined Behavior:
357357
///
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`.
360360
///
361361
/// * If the computed offset is non-zero, then `self` must be derived from a pointer to some
362362
/// [allocated object], and the entire memory range between `self` and the result must be in
@@ -399,7 +399,7 @@ impl<T: ?Sized> *const T {
399399
unsafe { intrinsics::offset(self, count) }
400400
}
401401

402-
/// Calculates the offset from a pointer in bytes.
402+
/// Adds a signed offset in bytes to a pointer.
403403
///
404404
/// `count` is in units of **bytes**.
405405
///
@@ -810,15 +810,19 @@ impl<T: ?Sized> *const T {
810810

811811
/// Adds an offset to a pointer.
812812
///
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+
///
813817
/// `count` is in units of T; e.g., a `count` of 3 represents a pointer
814818
/// offset of `3 * size_of::<T>()` bytes.
815819
///
816820
/// # Safety
817821
///
818822
/// If any of the following conditions are violated, the result is Undefined Behavior:
819823
///
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`.
822826
///
823827
/// * If the computed offset is non-zero, then `self` must be derived from a pointer to some
824828
/// [allocated object], and the entire memory range between `self` and the result must be in
@@ -861,7 +865,7 @@ impl<T: ?Sized> *const T {
861865
unsafe { intrinsics::offset(self, count) }
862866
}
863867

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.
865869
///
866870
/// `count` is in units of bytes.
867871
///
@@ -884,15 +888,19 @@ impl<T: ?Sized> *const T {
884888

885889
/// Subtracts an offset from a pointer.
886890
///
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+
///
887895
/// `count` is in units of T; e.g., a `count` of 3 represents a pointer
888896
/// offset of `3 * size_of::<T>()` bytes.
889897
///
890898
/// # Safety
891899
///
892900
/// If any of the following conditions are violated, the result is Undefined Behavior:
893901
///
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`.
896904
///
897905
/// * If the computed offset is non-zero, then `self` must be derived from a pointer to some
898906
/// [allocated object], and the entire memory range between `self` and the result must be in
@@ -943,8 +951,7 @@ impl<T: ?Sized> *const T {
943951
}
944952
}
945953

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.
948955
///
949956
/// `count` is in units of bytes.
950957
///

Diff for: library/core/src/ptr/mut_ptr.rs

+17-10
Original file line numberDiff line numberDiff line change
@@ -353,8 +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 (using unbounded arithmetic),
357-
/// must fit in an `isize`.
356+
/// * The offset in bytes, `count * size_of::<T>()`, computed on mathematical integers (without
357+
/// "wrapping around"), must fit in an `isize`.
358358
///
359359
/// * If the computed offset is non-zero, then `self` must be derived from a pointer to some
360360
/// [allocated object], and the entire memory range between `self` and the result must be in
@@ -399,7 +399,7 @@ impl<T: ?Sized> *mut T {
399399
unsafe { intrinsics::offset(self, count) }
400400
}
401401

402-
/// Calculates the offset from a pointer in bytes.
402+
/// Adds a signed offset in bytes to a pointer.
403403
///
404404
/// `count` is in units of **bytes**.
405405
///
@@ -891,15 +891,19 @@ impl<T: ?Sized> *mut T {
891891

892892
/// Adds an offset to a pointer.
893893
///
894+
/// This can only move the pointer forward (or not move it). If you need to move forward or
895+
/// backward depending on the value, then you might want [`offset`](#method.offset) instead
896+
/// which takes a signed offset.
897+
///
894898
/// `count` is in units of T; e.g., a `count` of 3 represents a pointer
895899
/// offset of `3 * size_of::<T>()` bytes.
896900
///
897901
/// # Safety
898902
///
899903
/// If any of the following conditions are violated, the result is Undefined Behavior:
900904
///
901-
/// * The computed offset, `count * size_of::<T>()` bytes (using unbounded arithmetic),
902-
/// must fit in an `isize`.
905+
/// * The offset in bytes, `count * size_of::<T>()`, computed on mathematical integers (without
906+
/// "wrapping around"), must fit in an `isize`.
903907
///
904908
/// * If the computed offset is non-zero, then `self` must be derived from a pointer to some
905909
/// [allocated object], and the entire memory range between `self` and the result must be in
@@ -942,7 +946,7 @@ impl<T: ?Sized> *mut T {
942946
unsafe { intrinsics::offset(self, count) }
943947
}
944948

945-
/// Calculates the offset from a pointer in bytes (convenience for `.byte_offset(count as isize)`).
949+
/// Adds an offset in bytes to a pointer.
946950
///
947951
/// `count` is in units of bytes.
948952
///
@@ -965,15 +969,19 @@ impl<T: ?Sized> *mut T {
965969

966970
/// Subtracts an offset from a pointer.
967971
///
972+
/// This can only move the pointer backward (or not move it). If you need to move forward or
973+
/// backward depending on the value, then you might want [`offset`](#method.offset) instead
974+
/// which takes a signed offset.
975+
///
968976
/// `count` is in units of T; e.g., a `count` of 3 represents a pointer
969977
/// offset of `3 * size_of::<T>()` bytes.
970978
///
971979
/// # Safety
972980
///
973981
/// If any of the following conditions are violated, the result is Undefined Behavior:
974982
///
975-
/// * The computed offset, `count * size_of::<T>()` bytes (using unbounded arithmetic),
976-
/// must fit in an `isize`.
983+
/// * The offset in bytes, `count * size_of::<T>()`, computed on mathematical integers (without
984+
/// "wrapping around"), must fit in an `isize`.
977985
///
978986
/// * If the computed offset is non-zero, then `self` must be derived from a pointer to some
979987
/// [allocated object], and the entire memory range between `self` and the result must be in
@@ -1024,8 +1032,7 @@ impl<T: ?Sized> *mut T {
10241032
}
10251033
}
10261034

1027-
/// Calculates the offset from a pointer in bytes (convenience for
1028-
/// `.byte_offset((count as isize).wrapping_neg())`).
1035+
/// Subtracts an offset in bytes from a pointer.
10291036
///
10301037
/// `count` is in units of bytes.
10311038
///

0 commit comments

Comments
 (0)