Skip to content

Commit 24ff8ae

Browse files
authored
Rollup merge of rust-lang#136259 - hkBst:patch-30, r=thomcc
Cleanup docs for Allocator This is an attempt to remove ungrammatical constructions and clean up the prose. I've sometimes had to try hard to understand what was being stated, so it is possible that I've misunderstood the original meaning. In particular, I did not see a difference between: - the borrow-checker lifetime of the allocator type itself. - as long as at least one of the allocator instance and all of its clones has not been dropped.
2 parents 83aa5c1 + 3830bbe commit 24ff8ae

File tree

1 file changed

+27
-31
lines changed

1 file changed

+27
-31
lines changed

core/src/alloc/mod.rs

+27-31
Original file line numberDiff line numberDiff line change
@@ -49,26 +49,26 @@ impl fmt::Display for AllocError {
4949
/// An implementation of `Allocator` can allocate, grow, shrink, and deallocate arbitrary blocks of
5050
/// data described via [`Layout`][].
5151
///
52-
/// `Allocator` is designed to be implemented on ZSTs, references, or smart pointers because having
53-
/// an allocator like `MyAlloc([u8; N])` cannot be moved, without updating the pointers to the
52+
/// `Allocator` is designed to be implemented on ZSTs, references, or smart pointers.
53+
/// An allocator for `MyAlloc([u8; N])` cannot be moved, without updating the pointers to the
5454
/// allocated memory.
5555
///
56-
/// Unlike [`GlobalAlloc`][], zero-sized allocations are allowed in `Allocator`. If an underlying
57-
/// allocator does not support this (like jemalloc) or return a null pointer (such as
58-
/// `libc::malloc`), this must be caught by the implementation.
56+
/// In contrast to [`GlobalAlloc`][], `Allocator` allows zero-sized allocations. If an underlying
57+
/// allocator does not support this (like jemalloc) or responds by returning a null pointer
58+
/// (such as `libc::malloc`), this must be caught by the implementation.
5959
///
6060
/// ### Currently allocated memory
6161
///
62-
/// Some of the methods require that a memory block be *currently allocated* via an allocator. This
63-
/// means that:
62+
/// Some of the methods require that a memory block is *currently allocated* by an allocator.
63+
/// This means that:
64+
/// * the starting address for that memory block was previously
65+
/// returned by [`allocate`], [`grow`], or [`shrink`], and
66+
/// * the memory block has not subsequently been deallocated.
6467
///
65-
/// * the starting address for that memory block was previously returned by [`allocate`], [`grow`], or
66-
/// [`shrink`], and
67-
///
68-
/// * the memory block has not been subsequently deallocated, where blocks are either deallocated
69-
/// directly by being passed to [`deallocate`] or were changed by being passed to [`grow`] or
70-
/// [`shrink`] that returns `Ok`. If `grow` or `shrink` have returned `Err`, the passed pointer
71-
/// remains valid.
68+
/// A memory block is deallocated by a call to [`deallocate`],
69+
/// or by a call to [`grow`] or [`shrink`] that returns `Ok`.
70+
/// A call to `grow` or `shrink` that returns `Err`,
71+
/// does not deallocate the memory block passed to it.
7272
///
7373
/// [`allocate`]: Allocator::allocate
7474
/// [`grow`]: Allocator::grow
@@ -77,32 +77,28 @@ impl fmt::Display for AllocError {
7777
///
7878
/// ### Memory fitting
7979
///
80-
/// Some of the methods require that a layout *fit* a memory block. What it means for a layout to
81-
/// "fit" a memory block means (or equivalently, for a memory block to "fit" a layout) is that the
80+
/// Some of the methods require that a `layout` *fit* a memory block or vice versa. This means that the
8281
/// following conditions must hold:
83-
///
84-
/// * The block must be allocated with the same alignment as [`layout.align()`], and
85-
///
86-
/// * The provided [`layout.size()`] must fall in the range `min ..= max`, where:
87-
/// - `min` is the size of the layout most recently used to allocate the block, and
88-
/// - `max` is the latest actual size returned from [`allocate`], [`grow`], or [`shrink`].
82+
/// * the memory block must be *currently allocated* with alignment of [`layout.align()`], and
83+
/// * [`layout.size()`] must fall in the range `min ..= max`, where:
84+
/// - `min` is the size of the layout used to allocate the block, and
85+
/// - `max` is the actual size returned from [`allocate`], [`grow`], or [`shrink`].
8986
///
9087
/// [`layout.align()`]: Layout::align
9188
/// [`layout.size()`]: Layout::size
9289
///
9390
/// # Safety
9491
///
95-
/// * Memory blocks returned from an allocator that are [*currently allocated*] must point to
96-
/// valid memory and retain their validity while they are [*currently allocated*] and the shorter
97-
/// of:
98-
/// - the borrow-checker lifetime of the allocator type itself.
99-
/// - as long as at least one of the instance and all of its clones has not been dropped.
92+
/// Memory blocks that are [*currently allocated*] by an allocator,
93+
/// must point to valid memory, and retain their validity while until either:
94+
/// - the memory block is deallocated, or
95+
/// - the allocator is dropped.
10096
///
101-
/// * copying, cloning, or moving the allocator must not invalidate memory blocks returned from this
102-
/// allocator. A copied or cloned allocator must behave like the same allocator, and
97+
/// Copying, cloning, or moving the allocator must not invalidate memory blocks returned from it
98+
/// A copied or cloned allocator must behave like the original allocator.
10399
///
104-
/// * any pointer to a memory block which is [*currently allocated*] may be passed to any other
105-
/// method of the allocator.
100+
/// A memory block which is [*currently allocated*] may be passed to
101+
/// any method of the allocator that accepts such an argument.
106102
///
107103
/// [*currently allocated*]: #currently-allocated-memory
108104
#[unstable(feature = "allocator_api", issue = "32838")]

0 commit comments

Comments
 (0)