Skip to content

Assorted allocator nitpicks - #161115

Open
nia-e wants to merge 10 commits into
rust-lang:mainfrom
nia-e:allocator-nitpicks
Open

Assorted allocator nitpicks#161115
nia-e wants to merge 10 commits into
rust-lang:mainfrom
nia-e:allocator-nitpicks

Conversation

@nia-e

@nia-e nia-e commented Aug 14, 2026

Copy link
Copy Markdown
Member

Small things that got missed in #157428, doc language cleanup for allocator, and a rename that closes #158344. cc @rust-lang/wg-allocators. pending libs bikeshed decision on the naming of into_raw_parts_with_alloc

r? clarfonthey

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Aug 14, 2026
Comment thread library/core/src/alloc/mod.rs
Comment thread library/alloc/src/vec/mod.rs
Comment thread library/core/src/alloc/mod.rs
@clarfonthey

Copy link
Copy Markdown
Contributor

r=me minus const bound note. (either remove unused const bound on both, or constify both)

@clarfonthey

clarfonthey commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

New changes look good too, but will hold merge in case you have anything else to add. (r=me)

@rust-log-analyzer

This comment has been minimized.

Comment thread library/core/src/alloc/mod.rs Outdated
Comment thread library/core/src/alloc/mod.rs Outdated
/// each other.
///
/// The following conditions are sufficient conditions for allocators to be equivalent.
/// The following conditions are necessary for allocators to be equivalent:

@theemathas theemathas Aug 15, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"sufficient conditions" is correct. There are other ways for allocators to become equivalent: a library can just "declare" extra equivalences.

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but such an equivalence still needs to uphold the points below, no? are we saying a library can declare e.g. a nontransitive equivalence?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per conversation elsewhere, we've agreed on the wording of "Users of allocators may assume the following are true of equivalent allocators, and implementors must ensure these rules are upheld:"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe something like: "Allocators must be equivalent if all the following conditions hold"

Sufficiency is correct, but the ambiguity is that the combination of all of them is sufficient, and not just any individual point by itself. In other words, all of the conditions are necessary if you want to use this method to ensure equivalence, but you can also just say they're equivalent otherwise.

Comment thread library/core/src/alloc/mod.rs Outdated
Comment on lines +107 to +108
/// * All (equivalent) allocators that this memory block is allocated with,
/// each has one of the following happen to them:
/// * *All* (equivalent) allocators that this memory block is allocated with has one of
/// the following happen to it:

@theemathas theemathas Aug 15, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My initial wording, with "each", was intentional — I wanted to specify that "one allocator gets dropped while another gets mutated" is enough for the memory to be invalidated.

View changes since the review

Comment thread library/core/src/alloc/mod.rs Outdated
/// the following happen to it:
/// * The allocator's destructor runs.
/// * The allocator is mutated through public API taking `&mut` access.
/// * The allocator is mutated through an untrusted API taking `&mut` access.

@theemathas theemathas Aug 15, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My previous wording was specifying that: if an allocator has a public method that doesn't specify what it does, then it must be assumed to potentially invalidate the allocations.

View changes since the review

@rust-log-analyzer

This comment has been minimized.

Comment on lines +144 to 150
/// Some of the methods require that a `layout` *fits* a memory block or vice versa. This means
/// that the following conditions must hold:
/// * the memory block must be *currently allocated* with alignment of [`layout.align()`], and
/// * [`layout.size()`] must fall in the range `min ..= max`, where:
/// - `min` is the size of the layout used to allocate the block, and
/// - `max` is the actual size returned from [`allocate`], [`allocate_zeroed`],
/// [`grow`], [`grow_zeroed`], or [`shrink`].

@N1ark N1ark Aug 15, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it worth reminding users here that max <= isize::MAX? actually not sure this matters here specifically tbh

View changes since the review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

with_allocator and with_alloc are named inconsistently.

6 participants