@@ -117,7 +117,7 @@ pub unsafe trait AllocRef {
117
117
/// [`handle_alloc_error`]: ../../alloc/alloc/fn.handle_alloc_error.html
118
118
fn alloc ( & mut self , layout : Layout ) -> Result < MemoryBlock , AllocErr > ;
119
119
120
- /// Behaves like `alloc`, but also ensures that the contents are set to zero before being returned .
120
+ /// Behaves like `alloc`, but also ensures that the returned memory is zero-initialized .
121
121
///
122
122
/// # Errors
123
123
///
@@ -156,20 +156,19 @@ pub unsafe trait AllocRef {
156
156
/// memory. The pointer is suitable for holding data described by a new layout with `layout`’s
157
157
/// alignment and a size given by `new_size`. To accomplish this, the allocator may extend the
158
158
/// allocation referenced by `ptr` to fit the new layout.
159
- ///~
159
+ ///
160
160
/// If this method returns `Err`, then ownership of the memory block has not been transferred to
161
161
/// this allocator, and the contents of the memory block are unaltered.
162
162
///
163
163
/// # Safety
164
164
///
165
165
/// * `ptr` must denote a block of memory [*currently allocated*] via this allocator,
166
166
/// * `layout` must [*fit*] that block of memory (The `new_size` argument need not fit it.),
167
- // We can't require that `new_size` is strictly greater than `memory.size` because of ZSTs.
168
- // An alternative would be
169
- // * `new_size must be strictly greater than `memory.size` or both are zero
170
167
/// * `new_size` must be greater than or equal to `layout.size()`, and
171
168
/// * `new_size`, when rounded up to the nearest multiple of `layout.align()`, must not overflow
172
169
/// (i.e., the rounded value must be less than or equal to `usize::MAX`).
170
+ // Note: We can't require that `new_size` is strictly greater than `layout.size()` because of ZSTs.
171
+ // alternative: `new_size must be strictly greater than `layout.size()` or both are zero
173
172
///
174
173
/// [*currently allocated*]: #currently-allocated-memory
175
174
/// [*fit*]: #memory-fitting
@@ -283,7 +282,7 @@ pub unsafe trait AllocRef {
283
282
// SAFETY: the caller must ensure that the `new_size` does not overflow.
284
283
// `layout.align()` comes from a `Layout` and is thus guaranteed to be valid for a Layout.
285
284
// The caller must ensure that `new_size` is greater than or equal to zero. If it's equal
286
- // to zero, it's catched beforehand.
285
+ // to zero, it's caught beforehand.
287
286
unsafe { Layout :: from_size_align_unchecked ( new_size, layout. align ( ) ) } ;
288
287
let new_memory = self . alloc_zeroed ( new_layout) ?;
289
288
0 commit comments