Skip to content

Commit

Permalink
Rollup merge of rust-lang#95546 - autumnontape:allocator-realloc-alig…
Browse files Browse the repository at this point in the history
…n-docs, r=Amanieu

add notes about alignment-altering reallocations to Allocator docs

As I said in rust-lang/wg-allocators#97, the fact that calls to `grow`, `grow_zeroed`, and `shrink` may request altered alignments is surprising and may be a pitfall for implementors of `Allocator` if it's left implicit. This pull request adds a note to the "Safety" section of each function's docs making it explicit.
  • Loading branch information
matthiaskrgr authored Apr 1, 2022
2 parents b81d235 + e246682 commit a92286f
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions library/core/src/alloc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ pub unsafe trait Allocator {
/// * `old_layout` must [*fit*] that block of memory (The `new_layout` argument need not fit it.).
/// * `new_layout.size()` must be greater than or equal to `old_layout.size()`.
///
/// Note that `new_layout.align()` need not be the same as `old_layout.align()`.
///
/// [*currently allocated*]: #currently-allocated-memory
/// [*fit*]: #memory-fitting
///
Expand Down Expand Up @@ -234,6 +236,8 @@ pub unsafe trait Allocator {
/// * `old_layout` must [*fit*] that block of memory (The `new_layout` argument need not fit it.).
/// * `new_layout.size()` must be greater than or equal to `old_layout.size()`.
///
/// Note that `new_layout.align()` need not be the same as `old_layout.align()`.
///
/// [*currently allocated*]: #currently-allocated-memory
/// [*fit*]: #memory-fitting
///
Expand Down Expand Up @@ -296,6 +300,8 @@ pub unsafe trait Allocator {
/// * `old_layout` must [*fit*] that block of memory (The `new_layout` argument need not fit it.).
/// * `new_layout.size()` must be smaller than or equal to `old_layout.size()`.
///
/// Note that `new_layout.align()` need not be the same as `old_layout.align()`.
///
/// [*currently allocated*]: #currently-allocated-memory
/// [*fit*]: #memory-fitting
///
Expand Down

0 comments on commit a92286f

Please sign in to comment.