ptr::add/sub: these are *not* equivalent to offset(count as isize)
This commit is contained in:
parent
a9fb00bfa4
commit
58350799a1
3 changed files with 19 additions and 16 deletions
|
|
@ -1425,8 +1425,7 @@ extern "rust-intrinsic" {
|
|||
///
|
||||
/// If the computed offset is non-zero, then both the starting and resulting pointer must be
|
||||
/// either in bounds or at the end of an allocated object. If either pointer is out
|
||||
/// of bounds or arithmetic overflow occurs then any further use of the returned value will
|
||||
/// result in undefined behavior.
|
||||
/// of bounds or arithmetic overflow occurs then this operation is undefined behavior.
|
||||
///
|
||||
/// The stabilized version of this intrinsic is [`pointer::offset`].
|
||||
#[must_use = "returns a new pointer rather than modifying its argument"]
|
||||
|
|
|
|||
|
|
@ -346,7 +346,7 @@ impl<T: ?Sized> *const T {
|
|||
if self.is_null() { None } else { Some(unsafe { &*(self as *const MaybeUninit<T>) }) }
|
||||
}
|
||||
|
||||
/// Adds an offset to a pointer.
|
||||
/// Adds a signed offset to a pointer.
|
||||
///
|
||||
/// `count` is in units of T; e.g., a `count` of 3 represents a pointer
|
||||
/// offset of `3 * size_of::<T>()` bytes.
|
||||
|
|
@ -355,7 +355,8 @@ impl<T: ?Sized> *const T {
|
|||
///
|
||||
/// If any of the following conditions are violated, the result is Undefined Behavior:
|
||||
///
|
||||
/// * The computed offset, `count * size_of::<T>()` bytes, must not overflow `isize`.
|
||||
/// * The computed offset, `count * size_of::<T>()` bytes (using unbounded arithmetic),
|
||||
/// must fit in an `isize`.
|
||||
///
|
||||
/// * If the computed offset is non-zero, then `self` must be derived from a pointer to some
|
||||
/// [allocated object], and the entire memory range between `self` and the result must be in
|
||||
|
|
@ -807,7 +808,7 @@ impl<T: ?Sized> *const T {
|
|||
}
|
||||
}
|
||||
|
||||
/// Adds an offset to a pointer (convenience for `.offset(count as isize)`).
|
||||
/// Adds an offset to a pointer.
|
||||
///
|
||||
/// `count` is in units of T; e.g., a `count` of 3 represents a pointer
|
||||
/// offset of `3 * size_of::<T>()` bytes.
|
||||
|
|
@ -816,7 +817,8 @@ impl<T: ?Sized> *const T {
|
|||
///
|
||||
/// If any of the following conditions are violated, the result is Undefined Behavior:
|
||||
///
|
||||
/// * The computed offset, `count * size_of::<T>()` bytes, must not overflow `isize`.
|
||||
/// * The computed offset, `count * size_of::<T>()` bytes (using unbounded arithmetic),
|
||||
/// must fit in an `isize`.
|
||||
///
|
||||
/// * If the computed offset is non-zero, then `self` must be derived from a pointer to some
|
||||
/// [allocated object], and the entire memory range between `self` and the result must be in
|
||||
|
|
@ -880,8 +882,7 @@ impl<T: ?Sized> *const T {
|
|||
unsafe { self.cast::<u8>().add(count).with_metadata_of(self) }
|
||||
}
|
||||
|
||||
/// Subtracts an offset from a pointer (convenience for
|
||||
/// `.offset((count as isize).wrapping_neg())`).
|
||||
/// Subtracts an offset from a pointer.
|
||||
///
|
||||
/// `count` is in units of T; e.g., a `count` of 3 represents a pointer
|
||||
/// offset of `3 * size_of::<T>()` bytes.
|
||||
|
|
@ -890,7 +891,8 @@ impl<T: ?Sized> *const T {
|
|||
///
|
||||
/// If any of the following conditions are violated, the result is Undefined Behavior:
|
||||
///
|
||||
/// * The computed offset, `count * size_of::<T>()` bytes, must not overflow `isize`.
|
||||
/// * The computed offset, `count * size_of::<T>()` bytes (using unbounded arithmetic),
|
||||
/// must fit in an `isize`.
|
||||
///
|
||||
/// * If the computed offset is non-zero, then `self` must be derived from a pointer to some
|
||||
/// [allocated object], and the entire memory range between `self` and the result must be in
|
||||
|
|
|
|||
|
|
@ -344,7 +344,7 @@ impl<T: ?Sized> *mut T {
|
|||
if self.is_null() { None } else { Some(unsafe { &*(self as *const MaybeUninit<T>) }) }
|
||||
}
|
||||
|
||||
/// Adds an offset to a pointer.
|
||||
/// Adds a signed offset to a pointer.
|
||||
///
|
||||
/// `count` is in units of T; e.g., a `count` of 3 represents a pointer
|
||||
/// offset of `3 * size_of::<T>()` bytes.
|
||||
|
|
@ -353,7 +353,8 @@ impl<T: ?Sized> *mut T {
|
|||
///
|
||||
/// If any of the following conditions are violated, the result is Undefined Behavior:
|
||||
///
|
||||
/// * The computed offset, `count * size_of::<T>()` bytes, must not overflow `isize`.
|
||||
/// * The computed offset, `count * size_of::<T>()` bytes (using unbounded arithmetic),
|
||||
/// must fit in an `isize`.
|
||||
///
|
||||
/// * If the computed offset is non-zero, then `self` must be derived from a pointer to some
|
||||
/// [allocated object], and the entire memory range between `self` and the result must be in
|
||||
|
|
@ -888,7 +889,7 @@ impl<T: ?Sized> *mut T {
|
|||
unsafe { (self as *const T).sub_ptr(origin) }
|
||||
}
|
||||
|
||||
/// Adds an offset to a pointer (convenience for `.offset(count as isize)`).
|
||||
/// Adds an offset to a pointer.
|
||||
///
|
||||
/// `count` is in units of T; e.g., a `count` of 3 represents a pointer
|
||||
/// offset of `3 * size_of::<T>()` bytes.
|
||||
|
|
@ -897,7 +898,8 @@ impl<T: ?Sized> *mut T {
|
|||
///
|
||||
/// If any of the following conditions are violated, the result is Undefined Behavior:
|
||||
///
|
||||
/// * The computed offset, `count * size_of::<T>()` bytes, must not overflow `isize`.
|
||||
/// * The computed offset, `count * size_of::<T>()` bytes (using unbounded arithmetic),
|
||||
/// must fit in an `isize`.
|
||||
///
|
||||
/// * If the computed offset is non-zero, then `self` must be derived from a pointer to some
|
||||
/// [allocated object], and the entire memory range between `self` and the result must be in
|
||||
|
|
@ -961,8 +963,7 @@ impl<T: ?Sized> *mut T {
|
|||
unsafe { self.cast::<u8>().add(count).with_metadata_of(self) }
|
||||
}
|
||||
|
||||
/// Subtracts an offset from a pointer (convenience for
|
||||
/// `.offset((count as isize).wrapping_neg())`).
|
||||
/// Subtracts an offset from a pointer.
|
||||
///
|
||||
/// `count` is in units of T; e.g., a `count` of 3 represents a pointer
|
||||
/// offset of `3 * size_of::<T>()` bytes.
|
||||
|
|
@ -971,7 +972,8 @@ impl<T: ?Sized> *mut T {
|
|||
///
|
||||
/// If any of the following conditions are violated, the result is Undefined Behavior:
|
||||
///
|
||||
/// * The computed offset, `count * size_of::<T>()` bytes, must not overflow `isize`.
|
||||
/// * The computed offset, `count * size_of::<T>()` bytes (using unbounded arithmetic),
|
||||
/// must fit in an `isize`.
|
||||
///
|
||||
/// * If the computed offset is non-zero, then `self` must be derived from a pointer to some
|
||||
/// [allocated object], and the entire memory range between `self` and the result must be in
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue