Skip to content

alloc: stabilise Allocator - #156882

Open
nia-e wants to merge 1 commit into
rust-lang:mainfrom
nia-e:stable-allocator
Open

alloc: stabilise Allocator#156882
nia-e wants to merge 1 commit into
rust-lang:mainfrom
nia-e:stable-allocator

Conversation

@nia-e

@nia-e nia-e commented May 24, 2026

Copy link
Copy Markdown
Member

View all comments

See the current proposed stabilisation report for up-to-date information on the proposed stable API.

outdated former status

Stabilise a bare-minimum (dyn-incompatible, but could be in the future) Allocator trait, alongside Box::new_in(), Vec::new_in(), the System & Global Allocators, and a blanket impl of Allocator for T: GlobalAlloc. For now, we should take care not to make it possible to instantiate anything other than a Vec or Box with custom allocators; it's Probably Fine, but worth a proper look before we rush in.

The soundness requirements for implementors were tightened to the most restrictive ones we could reasonably want per a conversation with @RalfJung.

This was discussed extensively at the all-hands with an apparent tentative consensus from libs and participating ecosystem stakeholders that the current design can be extended backwards-compatibly to address almost all usecases.

cc @rust-lang/libs @rust-lang/libs-api @rust-lang/opsem

r? libs

@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 May 24, 2026
@nia-e nia-e added A-allocators Area: Custom and system allocators relnotes Marks issues that should be documented in the release notes of the next release. S-waiting-on-fcp Status: PR is in FCP and is awaiting for FCP to complete. labels May 24, 2026
@nia-e nia-e added needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. and removed S-waiting-on-fcp Status: PR is in FCP and is awaiting for FCP to complete. labels May 24, 2026
@nia-e

nia-e commented May 24, 2026

Copy link
Copy Markdown
Member Author

r? @Amanieu

@rustbot rustbot assigned Amanieu and unassigned Mark-Simulacrum May 24, 2026
@rust-log-analyzer

This comment has been minimized.

Comment thread library/core/src/alloc/mod.rs Outdated
@nia-e
nia-e force-pushed the stable-allocator branch from ecf76bf to ed24b36 Compare May 24, 2026 17:42
Comment thread library/alloc/src/collections/binary_heap/mod.rs Outdated
Comment thread library/core/src/alloc/mod.rs Outdated
Comment thread library/core/src/alloc/global.rs Outdated
Comment thread tests/ui/allocator/not-an-allocator.u.stderr Outdated
Comment thread library/core/src/alloc/global.rs Outdated
Comment thread library/core/src/alloc/mod.rs Outdated
@theemathas

Copy link
Copy Markdown
Contributor

I believe the safety requirements are not yet correct. See #156544

@jmillikin

This comment has been minimized.

@bushrat011899

This comment has been minimized.

@jmillikin

This comment has been minimized.

@bushrat011899

This comment has been minimized.

@jmillikin

This comment has been minimized.

@bushrat011899

This comment has been minimized.

@joshtriplett

This comment was marked as outdated.

@rust-rfcbot

This comment was marked as outdated.

@nia-e nia-e added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed I-libs-nominated Nominated for discussion during a libs team meeting. S-waiting-on-t-libs Status: Awaiting decision from T-libs labels Aug 18, 2026
@nia-e

nia-e commented Aug 18, 2026

Copy link
Copy Markdown
Member Author

So, per today's libs meeting: @programmerjake the team was in favour of adding all the methods you suggest to the stabilisation, so hooray. We're waiting on #161115 merging (it has already been approved) which is itself just some typo fixes, but then this should be able to land. Hooray!

@rust-bors

This comment has been minimized.

@nia-e
nia-e force-pushed the stable-allocator branch from 3509043 to 7290501 Compare August 19, 2026 16:30
@rustbot rustbot added the T-clippy Relevant to the Clippy team. label Aug 19, 2026
@rustbot

This comment has been minimized.

@nia-e

nia-e commented Aug 19, 2026

Copy link
Copy Markdown
Member Author

I believe FCP is ready to be opened; the proposed-for-stabilisation bits are listed in the report. In brief:

  • Allocator trait;
  • Box<T, A> & Vec<T, A> + a couple methods on these;
  • System & Global allocators.

The libs+libs-api ask is "are these indeed the APIs we want?" and the vibe seems to be positive. The lang ask is "can we commit to Box never being fundamental in A, given that changing this would be breaking later?" (context, context) and again the vibe appeared positive last time this was brought up ^^

@RalfJung

RalfJung commented Aug 19, 2026

Copy link
Copy Markdown
Member

Also on the lang side is committing to Box being "funny" around aliasing requirements -- it has them for A = Global (and maybe for A = NativeAllocator<T> in the future) but not for other allocators.

@nia-e nia-e added S-waiting-on-t-libs Status: Awaiting decision from T-libs S-waiting-on-t-lang Status: Awaiting decision from T-lang I-lang-nominated Nominated for discussion during a lang team meeting. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 19, 2026
@rust-log-analyzer

This comment has been minimized.

Comment thread library/alloc/src/vec/mod.rs Outdated
@Amanieu

Amanieu commented Aug 20, 2026

Copy link
Copy Markdown
Member

I believe FCP is ready to be opened; the proposed-for-stabilisation bits are listed in the report. In brief:

  • Allocator trait;

  • Box<T, A> & Vec<T, A> + a couple methods on these;

  • System & Global allocators.

The libs+libs-api ask is "are these indeed the APIs we want?" and the vibe seems to be positive. The lang ask is "can we commit to Box never being fundamental in A, given that changing this would be breaking later?" (context, context) and again the vibe appeared positive last time this was brought up ^^

Thanks @nia-e for pushing this through!

@rfcbot merge lang,libs-api

@rust-rfcbot

rust-rfcbot commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator

@Amanieu has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns.
See this document for info about what commands tagged team members can give me.

@rust-rfcbot rust-rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Aug 20, 2026
@nia-e

nia-e commented Aug 20, 2026

Copy link
Copy Markdown
Member Author

cc also @rust-lang/libs-api + @rust-lang/lang

@traviscross

Copy link
Copy Markdown
Contributor

Do we intend (now or later) to make any ABI guarantees about Box<T, A> where A ≠ Global?

@RalfJung

RalfJung commented Aug 20, 2026

Copy link
Copy Markdown
Member

I'd be fine with making guarantees for the case where A has trivial ABI. Beyond that -- probably not.

@traviscross

Copy link
Copy Markdown
Contributor

Should we be firing improper_ctypes_definitions?

@rust-bors

This comment has been minimized.

@nia-e

nia-e commented Aug 20, 2026

Copy link
Copy Markdown
Member Author

I'm happy having them under that lint

@rustbot

rustbot commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

Comment thread library/alloc/src/sync.rs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-allocators Area: Custom and system allocators A-run-make Area: port run-make Makefiles to rmake.rs disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. I-lang-nominated Nominated for discussion during a lang team meeting. proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. relnotes Marks issues that should be documented in the release notes of the next release. S-waiting-on-t-lang Status: Awaiting decision from T-lang S-waiting-on-t-libs Status: Awaiting decision from T-libs T-clippy Relevant to the Clippy team. T-lang Relevant to the language team 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.