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
Copy link
Copy Markdown
Member

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

Stabilise a bare-minimum (dyn-incompatible, but could be in the future) Allocator trait, alongside Box::new_in(), Vec::new_in(), the System Allocator impl, 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 tenative 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
Copy link
Copy Markdown
Member Author

nia-e commented May 24, 2026

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
/// let heap : BinaryHeap<i32, System> = BinaryHeap::new_in(System);
/// ```
#[unstable(feature = "allocator_api", issue = "32838")]
#[rustc_const_unstable(feature = "allocator_api", issue = "32838")]
Copy link
Copy Markdown
Member

@programmerjake programmerjake May 24, 2026

Choose a reason for hiding this comment

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

isn't this implied by #[unstable]?

View changes since the review

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.

No.

Comment on lines +394 to +397
/// Dummy function. Used to make `Allocator` non-`dyn` compatible for now.
#[doc(hidden)]
#[unstable(feature = "allocator_api", issue = "32838")]
fn dummy_no_dyn() {}
Copy link
Copy Markdown
Member

@fmease fmease May 24, 2026

Choose a reason for hiding this comment

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

Instead, you could add #[rustc_dyn_incompatible_trait] to the trait. That would also improve diagnostics.

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.

yeah that's a pure brain fart on my end :D ty

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 needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. relnotes Marks issues that should be documented in the release notes of the next release. 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.

9 participants