@@ -119,7 +119,7 @@ pub enum ReallocPlacement {
119
119
///
120
120
/// Unlike [`GlobalAlloc`][], zero-sized allocations are allowed in `AllocRef`. If an underlying
121
121
/// allocator does not support this (like jemalloc) or return a null pointer (such as
122
- /// `libc::malloc`), this case must be caught.
122
+ /// `libc::malloc`), this must be caught by the implementation .
123
123
///
124
124
/// ### Currently allocated memory
125
125
///
@@ -157,18 +157,20 @@ pub enum ReallocPlacement {
157
157
/// # Safety
158
158
///
159
159
/// * Memory blocks returned from an allocator must point to valid memory and retain their validity
160
- /// until the instance and all of its clones are dropped, and
160
+ /// until the instance and all of its clones are dropped,
161
161
///
162
162
/// * cloning or moving the allocator must not invalidate memory blocks returned from this
163
- /// allocator. A cloned allocator must behave like the same allocator.
163
+ /// allocator. A cloned allocator must behave like the same allocator, and
164
164
///
165
165
/// * any pointer to a memory block which is [*currently allocated*] may be passed to any other
166
166
/// method of the allocator.
167
167
///
168
168
/// [*currently allocated*]: #currently-allocated-memory
169
169
#[ unstable( feature = "allocator_api" , issue = "32838" ) ]
170
170
pub unsafe trait AllocRef {
171
- /// On success, returns a memory block meeting the size and alignment guarantees of `layout`.
171
+ /// Attempts to allocate a block of memory.
172
+ ///
173
+ /// On success, returns a [`MemoryBlock`][] meeting the size and alignment guarantees of `layout`.
172
174
///
173
175
/// The returned block may have a larger size than specified by `layout.size()` and is
174
176
/// initialized as specified by [`init`], all the way up to the returned size of the block.
@@ -190,26 +192,26 @@ pub unsafe trait AllocRef {
190
192
/// [`handle_alloc_error`]: ../../alloc/alloc/fn.handle_alloc_error.html
191
193
fn alloc ( & mut self , layout : Layout , init : AllocInit ) -> Result < MemoryBlock , AllocErr > ;
192
194
193
- /// Deallocates the memory denoted by `memory `.
195
+ /// Deallocates the memory referenced by `ptr `.
194
196
///
195
197
/// # Safety
196
198
///
197
- /// * `ptr` must be [*currently allocated*] via this allocator, and
198
- /// * `layout` must [*fit*] the `ptr` .
199
+ /// * `ptr` must denote a block of memory [*currently allocated*] via this allocator, and
200
+ /// * `layout` must [*fit*] that block of memory .
199
201
///
200
202
/// [*currently allocated*]: #currently-allocated-memory
201
203
/// [*fit*]: #memory-fitting
202
204
unsafe fn dealloc ( & mut self , ptr : NonNull < u8 > , layout : Layout ) ;
203
205
204
206
/// Attempts to extend the memory block.
205
207
///
206
- /// Returns a new memory block containing a pointer and the actual size of the allocated
207
- /// block . The pointer is suitable for holding data described by a new layout with `layout`’s
208
+ /// Returns a new [`MemoryBlock`][] containing a pointer and the actual size of the allocated
209
+ /// memory . The pointer is suitable for holding data described by a new layout with `layout`’s
208
210
/// alignment and a size given by `new_size`. To accomplish this, the allocator may extend the
209
211
/// allocation referenced by `ptr` to fit the new layout. If the [`placement`] is
210
212
/// [`InPlace`], the returned pointer is guaranteed to be the same as the passed `ptr`.
211
213
///
212
- /// If `ReallocPlacement:: MayMove` is used then ownership of the memory block referenced by `ptr`
214
+ /// If [` MayMove`] is used then ownership of the memory block referenced by `ptr`
213
215
/// is transferred to this allocator. The memory may or may not be freed, and should be
214
216
/// considered unusable (unless of course it is transferred back to the caller again via the
215
217
/// return value of this method).
@@ -227,17 +229,18 @@ pub unsafe trait AllocRef {
227
229
/// the size of the `MemoryBlock` returned by the `grow` call.
228
230
///
229
231
/// [`InPlace`]: ReallocPlacement::InPlace
232
+ /// [`MayMove`]: ReallocPlacement::MayMove
230
233
/// [`placement`]: ReallocPlacement
231
234
/// [`init`]: AllocInit
232
235
///
233
236
/// # Safety
234
237
///
235
- /// * `ptr` must be [*currently allocated*] via this allocator,
236
- /// * `layout` must [*fit*] the `ptr`. (The `new_size` argument need not fit it.)
238
+ /// * `ptr` must denote a block of memory [*currently allocated*] via this allocator,
239
+ /// * `layout` must [*fit*] that block of memory (The `new_size` argument need not fit it.),
237
240
// We can't require that `new_size` is strictly greater than `memory.size` because of ZSTs.
238
241
// An alternative would be
239
242
// * `new_size must be strictly greater than `memory.size` or both are zero
240
- /// * `new_size` must be greater than or equal to `layout.size()`
243
+ /// * `new_size` must be greater than or equal to `layout.size()`, and
241
244
/// * `new_size`, when rounded up to the nearest multiple of `layout.align()`, must not overflow
242
245
/// (i.e., the rounded value must be less than or equal to `usize::MAX`).
243
246
///
@@ -289,8 +292,8 @@ pub unsafe trait AllocRef {
289
292
290
293
/// Attempts to shrink the memory block.
291
294
///
292
- /// Returns a new memory block containing a pointer and the actual size of the allocated
293
- /// block . The pointer is suitable for holding data described by a new layout with `layout`’s
295
+ /// Returns a new [`MemoryBlock`][] containing a pointer and the actual size of the allocated
296
+ /// memory . The pointer is suitable for holding data described by a new layout with `layout`’s
294
297
/// alignment and a size given by `new_size`. To accomplish this, the allocator may shrink the
295
298
/// allocation referenced by `ptr` to fit the new layout. If the [`placement`] is
296
299
/// [`InPlace`], the returned pointer is guaranteed to be the same as the passed `ptr`.
@@ -310,20 +313,20 @@ pub unsafe trait AllocRef {
310
313
///
311
314
/// # Safety
312
315
///
313
- /// * `ptr` must be [*currently allocated*] via this allocator,
314
- /// * `layout` must [*fit*] the `ptr`. (The `new_size` argument need not fit it.)
316
+ /// * `ptr` must denote a block of memory [*currently allocated*] via this allocator,
317
+ /// * `layout` must [*fit*] that block of memory (The `new_size` argument need not fit it.), and
315
318
// We can't require that `new_size` is strictly smaller than `memory.size` because of ZSTs.
316
319
// An alternative would be
317
320
// * `new_size must be strictly smaller than `memory.size` or both are zero
318
- /// * `new_size` must be smaller than or equal to `layout.size()`
321
+ /// * `new_size` must be smaller than or equal to `layout.size()`.
319
322
///
320
323
/// [*currently allocated*]: #currently-allocated-memory
321
324
/// [*fit*]: #memory-fitting
322
325
///
323
326
/// # Errors
324
327
///
325
328
/// Returns `Err` if the new layout does not meet the allocator's size and alignment
326
- /// constraints of the allocator, or if growing otherwise fails.
329
+ /// constraints of the allocator, or if shrinking otherwise fails.
327
330
///
328
331
/// Implementations are encouraged to return `Err` on memory exhaustion rather than panicking or
329
332
/// aborting, but this is not a strict requirement. (Specifically: it is *legal* to implement
0 commit comments