Skip to content

Commit b164f66

Browse files
committed
rollup merge of #24610: nagisa/offset-docs
2 parents 551a74d + 82b4356 commit b164f66

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/libcore/intrinsics.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,17 @@ extern "rust-intrinsic" {
255255
/// Returns `true` if a type is managed (will be allocated on the local heap)
256256
pub fn owns_managed<T>() -> bool;
257257

258-
/// Calculates the offset from a pointer. The offset *must* be in-bounds of
259-
/// the object, or one-byte-past-the-end. An arithmetic overflow is also
260-
/// undefined behaviour.
258+
/// Calculates the offset from a pointer.
261259
///
262260
/// This is implemented as an intrinsic to avoid converting to and from an
263261
/// integer, since the conversion would throw away aliasing information.
262+
///
263+
/// # Safety
264+
///
265+
/// Both the starting and resulting pointer must be either in bounds or one
266+
/// byte past the end of an allocated object. If either pointer is out of
267+
/// bounds or arithmetic overflow occurs then any further use of the
268+
/// returned value will result in undefined behavior.
264269
pub fn offset<T>(dst: *const T, offset: isize) -> *const T;
265270

266271
/// Copies `count * size_of<T>` bytes from `src` to `dst`. The source

src/libcore/ptr.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,10 @@ impl<T: ?Sized> *const T {
284284
///
285285
/// # Safety
286286
///
287-
/// The offset must be in-bounds of the object, or one-byte-past-the-end.
288-
/// Otherwise `offset` invokes Undefined Behaviour, regardless of whether
289-
/// the pointer is used.
287+
/// Both the starting and resulting pointer must be either in bounds or one
288+
/// byte past the end of an allocated object. If either pointer is out of
289+
/// bounds or arithmetic overflow occurs then
290+
/// any further use of the returned value will result in undefined behavior.
290291
#[stable(feature = "rust1", since = "1.0.0")]
291292
#[inline]
292293
pub unsafe fn offset(self, count: isize) -> *const T where T: Sized {

0 commit comments

Comments
 (0)