Skip to content

Commit 1b9f420

Browse files
authored
Rollup merge of #82628 - vakaras:realloc-doc, r=Mark-Simulacrum
Try to clarify GlobalAlloc::realloc documentation comment. This PR tries to improve the documentation of [GlobalAlloc::realloc](https://doc.rust-lang.org/alloc/alloc/trait.GlobalAlloc.html#method.realloc) with two aspects: 1. Explicitly mention that `realloc` preserves the contents of the original memory block. 2. Explicitly mention which layout should be used to deallocate the reallocated block.
2 parents d65b231 + cdfff98 commit 1b9f420

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

library/core/src/alloc/global.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ pub unsafe trait GlobalAlloc {
122122
/// this allocator,
123123
///
124124
/// * `layout` must be the same layout that was used
125-
/// to allocate that block of memory,
125+
/// to allocate that block of memory.
126126
#[stable(feature = "global_alloc", since = "1.28.0")]
127127
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout);
128128

@@ -167,7 +167,10 @@ pub unsafe trait GlobalAlloc {
167167
/// and should be considered unusable (unless of course it was
168168
/// transferred back to the caller again via the return value of
169169
/// this method). The new memory block is allocated with `layout`, but
170-
/// with the `size` updated to `new_size`.
170+
/// with the `size` updated to `new_size`. This new layout should be
171+
/// used when deallocating the new memory block with `dealloc`. The range
172+
/// `0..min(layout.size(), new_size)` of the new memory block is
173+
/// guaranteed to have the same values as the original block.
171174
///
172175
/// If this method returns null, then ownership of the memory
173176
/// block has not been transferred to this allocator, and the

0 commit comments

Comments
 (0)