Skip to content

Commit 50a20dc

Browse files
committed
offset: allow zero-byte offset on arbitrary pointers
1 parent 41fe75e commit 50a20dc

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

library/core/src/intrinsics.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1421,10 +1421,10 @@ extern "rust-intrinsic" {
14211421
///
14221422
/// # Safety
14231423
///
1424-
/// Both the starting and resulting pointer must be either in bounds or one
1425-
/// byte past the end of an allocated object. If either pointer is out of
1426-
/// bounds or arithmetic overflow occurs then any further use of the
1427-
/// returned value will result in undefined behavior.
1424+
/// If the computed offset is non-zero, then both the starting and resulting pointer must be
1425+
/// either in bounds or one byte past the end of an allocated object. If either pointer is out
1426+
/// of bounds or arithmetic overflow occurs then any further use of the returned value will
1427+
/// result in undefined behavior.
14281428
///
14291429
/// The stabilized version of this intrinsic is [`pointer::offset`].
14301430
#[must_use = "returns a new pointer rather than modifying its argument"]

library/core/src/ptr/const_ptr.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,8 @@ impl<T: ?Sized> *const T {
416416
/// If any of the following conditions are violated, the result is Undefined
417417
/// Behavior:
418418
///
419-
/// * Both the starting and resulting pointer must be either in bounds or one
420-
/// byte past the end of the same [allocated object].
419+
/// * If the computed offset is non-zero, then both the starting and resulting pointer must be
420+
/// either in bounds or one byte past the end of the same [allocated object].
421421
///
422422
/// * The computed offset, **in bytes**, cannot overflow an `isize`.
423423
///
@@ -891,8 +891,8 @@ impl<T: ?Sized> *const T {
891891
/// If any of the following conditions are violated, the result is Undefined
892892
/// Behavior:
893893
///
894-
/// * Both the starting and resulting pointer must be either in bounds or one
895-
/// byte past the end of the same [allocated object].
894+
/// * If the computed offset is non-zero, then both the starting and resulting pointer must be
895+
/// either in bounds or one byte past the end of the same [allocated object].
896896
///
897897
/// * The computed offset, **in bytes**, cannot overflow an `isize`.
898898
///
@@ -975,8 +975,8 @@ impl<T: ?Sized> *const T {
975975
/// If any of the following conditions are violated, the result is Undefined
976976
/// Behavior:
977977
///
978-
/// * Both the starting and resulting pointer must be either in bounds or one
979-
/// byte past the end of the same [allocated object].
978+
/// * If the computed offset is non-zero, then both the starting and resulting pointer must be
979+
/// either in bounds or one byte past the end of the same [allocated object].
980980
///
981981
/// * The computed offset cannot exceed `isize::MAX` **bytes**.
982982
///

library/core/src/ptr/mut_ptr.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,8 @@ impl<T: ?Sized> *mut T {
429429
/// If any of the following conditions are violated, the result is Undefined
430430
/// Behavior:
431431
///
432-
/// * Both the starting and resulting pointer must be either in bounds or one
433-
/// byte past the end of the same [allocated object].
432+
/// * If the computed offset is non-zero, then both the starting and resulting pointer must be
433+
/// either in bounds or one byte past the end of the same [allocated object].
434434
///
435435
/// * The computed offset, **in bytes**, cannot overflow an `isize`.
436436
///
@@ -992,8 +992,8 @@ impl<T: ?Sized> *mut T {
992992
/// If any of the following conditions are violated, the result is Undefined
993993
/// Behavior:
994994
///
995-
/// * Both the starting and resulting pointer must be either in bounds or one
996-
/// byte past the end of the same [allocated object].
995+
/// * If the computed offset is non-zero, then both the starting and resulting pointer must be
996+
/// either in bounds or one byte past the end of the same [allocated object].
997997
///
998998
/// * The computed offset, **in bytes**, cannot overflow an `isize`.
999999
///
@@ -1076,8 +1076,8 @@ impl<T: ?Sized> *mut T {
10761076
/// If any of the following conditions are violated, the result is Undefined
10771077
/// Behavior:
10781078
///
1079-
/// * Both the starting and resulting pointer must be either in bounds or one
1080-
/// byte past the end of the same [allocated object].
1079+
/// * If the computed offset is non-zero, then both the starting and resulting pointer must be
1080+
/// either in bounds or one byte past the end of the same [allocated object].
10811081
///
10821082
/// * The computed offset cannot exceed `isize::MAX` **bytes**.
10831083
///

0 commit comments

Comments
 (0)