Skip to content

Unstably implement StaticAllocator on fundamental types - #166221

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
maxdexh:reserve-fundamental-static-alloc-impls
Nov 23, 2026
Merged

rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
maxdexh:reserve-fundamental-static-alloc-impls

Conversation

@maxdexh

@maxdexh maxdexh commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Unstably implements StaticAllocator on Box and Pin.

These types are fundamental, and we use StaticAllocator in bounds (specifically impl From<Box<T, A>> for Pin<Box<T, A>> where A: StaticAllocator, so adding impls for them would generally be already breaking due to coherence.

The impls here are barely not breaking, because all StaticAllocator implementors are currently considered local to std, so any code that tries to observe the non-existence of these impls through coherence fails with something like "upstream could add a StaticAllocator impl to Box<Global>". This isn't really ideal, so to prevent any accidents in the future, this PR adds these #[unstable_feature_bound] impls.

The impl for Box could be added stably, but I'd rather do that in a separate PR, because doing so would require FCP (it would allow Box::into_pin(Box::new_in(1, Box::new(Global)))), and I don't want this semver risk at the back of my mind for weeks.

The impl for Pin is not correct, and only meant as a reservation impl (hence the separate "internal_" feature gate). See the FIXME comment above it.

r? clarfonthey

@rustbot rustbot added A-allocators Area: Custom and system allocators 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 Nov 19, 2026
///
/// This trait impl is unstable and only usable on nightly with `feature(allocator_ext)`.
/// It may be changed or removed in the future.
// FIXME: We may want to weaken the `Allocator` bound here to some `PinnedAllocator`

@maxdexh maxdexh Nov 19, 2026 •

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.

Also added this fixme here because we discussed this on zulip at some point and will probably forget it.

View changes since the review

@rust-log-analyzer

This comment was marked as resolved.

@maxdexh
maxdexh force-pushed the reserve-fundamental-static-alloc-impls branch from c359b94 to d0b06ce Compare November 19, 2026 19:37
@rustbot rustbot added the A-box Area: Our favorite opsem complication label Nov 19, 2026
@maxdexh
maxdexh force-pushed the reserve-fundamental-static-alloc-impls branch from d0b06ce to 80ed9e0 Compare November 19, 2026 19:39
@rust-log-analyzer

This comment has been minimized.

@maxdexh
maxdexh force-pushed the reserve-fundamental-static-alloc-impls branch 2 times, most recently from 6e73623 to ae0b40a Compare November 19, 2026 19:53
@rust-log-analyzer

This comment was marked as resolved.

@maxdexh
maxdexh force-pushed the reserve-fundamental-static-alloc-impls branch from ae0b40a to 4046033 Compare November 19, 2026 20:45
@clarfonthey

Copy link
Copy Markdown
Contributor

Yeah, okay.

@bors r+ rollup

@rust-bors

rust-bors Bot commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 4046033 has been approved by clarfonthey

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 23, 2026
rust-bors Bot pushed a commit that referenced this pull request Nov 23, 2026
Rollup of 5 pull requests

Successful merges:

 - #164537 (Parser: Clean up `parse_expr_dot_or_call_with` & simplify `parse_expr_prefix`)
 - #165481 (Separate `Primitive::Bool` and make `#[repr($int)]` enums always use the ABI of $int)
 - #166290 (Require the next-solver for unsafe binders)
 - #165865 (Move more rustc lint attributes to lint helpers.)
 - #166221 (Unstably implement `StaticAllocator` on fundamental types)
@rust-bors
rust-bors Bot merged commit 4e73e06 into rust-lang:main Nov 23, 2026
14 checks passed
@rustbot rustbot added this to the 1.102.0 milestone Nov 23, 2026
rust-bors Bot pushed a commit that referenced this pull request Nov 23, 2026
Rollup merge of #166221 - maxdexh:reserve-fundamental-static-alloc-impls, r=clarfonthey

Unstably implement `StaticAllocator` on fundamental types

Unstably implements `StaticAllocator` on `Box` and `Pin`.

These types are fundamental, and we use `StaticAllocator` in bounds (specifically `impl From<Box<T, A>> for Pin<Box<T, A>> where A: StaticAllocator`, so adding impls for them would generally be already breaking due to coherence.

The impls here are barely not breaking, because all `StaticAllocator` implementors are currently considered local to std, so any code that tries to observe the non-existence of these impls through coherence fails with something like "upstream could add a `StaticAllocator` impl to `Box<Global>`". This isn't really ideal, so to prevent any accidents in the future, this PR adds these `#[unstable_feature_bound]` impls.

The impl for `Box` could be added stably, but I'd rather do that in a separate PR, because doing so would require FCP (it would allow `Box::into_pin(Box::new_in(1, Box::new(Global)))`), and I don't want this semver risk at the back of my mind for weeks.

The impl for `Pin` is not correct, and only meant as a reservation impl (hence the separate "`internal_`" feature gate). See the `FIXME` comment above it.

r? clarfonthey
bjorn3 pushed a commit to rust-lang/rustc_codegen_cranelift that referenced this pull request Nov 24, 2026
Rollup of 5 pull requests

Successful merges:

 - rust-lang/rust#164537 (Parser: Clean up `parse_expr_dot_or_call_with` & simplify `parse_expr_prefix`)
 - rust-lang/rust#165481 (Separate `Primitive::Bool` and make `#[repr($int)]` enums always use the ABI of $int)
 - rust-lang/rust#166290 (Require the next-solver for unsafe binders)
 - rust-lang/rust#165865 (Move more rustc lint attributes to lint helpers.)
 - rust-lang/rust#166221 (Unstably implement `StaticAllocator` on fundamental types)
mehmettoplu-rs pushed a commit to mehmettoplu-rs/miri that referenced this pull request Nov 24, 2026
Rollup of 5 pull requests

Successful merges:

 - rust-lang/rust#164537 (Parser: Clean up `parse_expr_dot_or_call_with` & simplify `parse_expr_prefix`)
 - rust-lang/rust#165481 (Separate `Primitive::Bool` and make `#[repr($int)]` enums always use the ABI of $int)
 - rust-lang/rust#166290 (Require the next-solver for unsafe binders)
 - rust-lang/rust#165865 (Move more rustc lint attributes to lint helpers.)
 - rust-lang/rust#166221 (Unstably implement `StaticAllocator` on fundamental types)
mehmettoplu-rs pushed a commit to mehmettoplu-rs/rustc_codegen_gcc that referenced this pull request Nov 27, 2026
Rollup of 5 pull requests

Successful merges:

 - rust-lang/rust#164537 (Parser: Clean up `parse_expr_dot_or_call_with` & simplify `parse_expr_prefix`)
 - rust-lang/rust#165481 (Separate `Primitive::Bool` and make `#[repr($int)]` enums always use the ABI of $int)
 - rust-lang/rust#166290 (Require the next-solver for unsafe binders)
 - rust-lang/rust#165865 (Move more rustc lint attributes to lint helpers.)
 - rust-lang/rust#166221 (Unstably implement `StaticAllocator` on fundamental types)
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-box Area: Our favorite opsem complication S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

4 participants