Skip to content

Commit 80873ae

Browse files
committed
Rollup merge of #33335 - cramertj:master, r=alexcrichton
docs: Changed docs for `size_of` to describe size as a stride offset Current documentation for `std::mem::size_of` is ambiguous, and the documentation for `std::intrinsics::size_of` incorrectly defines size. This fix re-defines size as the offset in bytes between successive instances of a type, as described in LLVM's [getTypeAllocSize](http://llvm.org/docs/doxygen/html/classllvm_1_1DataLayout.html#a1d6fcc02e91ba24510aba42660c90e29). Fixes: #33266
2 parents 6dfe033 + 38c8836 commit 80873ae

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/libcore/intrinsics.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,8 @@ extern "rust-intrinsic" {
192192

193193
/// The size of a type in bytes.
194194
///
195-
/// This is the exact number of bytes in memory taken up by a
196-
/// value of the given type. In other words, a memset of this size
197-
/// would *exactly* overwrite a value. When laid out in vectors
198-
/// and structures there may be additional padding between
199-
/// elements.
195+
/// More specifically, this is the offset in bytes between successive
196+
/// items of the same type, including alignment padding.
200197
pub fn size_of<T>() -> usize;
201198

202199
/// Moves a value to an uninitialized memory location.

src/libcore/mem.rs

+3
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ pub fn forget<T>(t: T) {
117117

118118
/// Returns the size of a type in bytes.
119119
///
120+
/// More specifically, this is the offset in bytes between successive
121+
/// items of the same type, including alignment padding.
122+
///
120123
/// # Examples
121124
///
122125
/// ```

0 commit comments

Comments
 (0)