Skip to content

Commit 000cda6

Browse files
committed
auto merge of #11002 : pnkfelix/rust/fsk-improve-doc-for-ptr-offset, r=alexcrichton
Spell out the units used for the `offset` argument, so that people do not try to scale to units of bytes themselves.
2 parents 35e5056 + 16f69b2 commit 000cda6

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/libstd/ptr.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,18 @@ use util::swap;
2121

2222
#[cfg(not(test))] use cmp::{Eq, Ord};
2323

24-
/// Calculate the offset from a pointer
24+
/// Calculate the offset from a pointer.
25+
/// The `count` argument is in units of T; e.g. a `count` of 3
26+
/// represents a pointer offset of `3 * sizeof::<T>()` bytes.
2527
#[inline]
2628
pub unsafe fn offset<T>(ptr: *T, count: int) -> *T {
2729
intrinsics::offset(ptr, count)
2830
}
2931

3032
/// Calculate the offset from a mut pointer. The count *must* be in bounds or
3133
/// otherwise the loads of this address are undefined.
34+
/// The `count` argument is in units of T; e.g. a `count` of 3
35+
/// represents a pointer offset of `3 * sizeof::<T>()` bytes.
3236
#[inline]
3337
pub unsafe fn mut_offset<T>(ptr: *mut T, count: int) -> *mut T {
3438
intrinsics::offset(ptr as *T, count) as *mut T

0 commit comments

Comments
 (0)